事象
題名の通り、UIAlertController を -presentViewController:animated:completion: しようとすると UIAlertController:supportedInterfaceOrientations was invoked recursively! のログを吐きつつクラッシュする。
対応
以下のサブクラスを作成し、使用するように変更。
OSAlertController.h
#import <UIKit/UIKit.h>
@interface OSAlertController : UIAlertController
- (instancetype)initWithOrientationMask:(UIInterfaceOrientationMask)orientationMask;
@end
OSAlertController.m
#import "OSAlertController.h"
@interface OSAlertController ()
@property (nonatomic) UIInterfaceOrientationMask orientationMask;
@end
@implementation OSAlertController
- (instancetype)init {
self = [super init];
if (self) {
[self setOrientationMask:UIInterfaceOrientationMaskAllButUpsideDown];
}
return self;
}
- (instancetype)initWithOrientationMask:(UIInterfaceOrientationMask)orientationMask {
self = [super init];
if (self) {
[self setOrientationMask:orientationMask];
}
return self;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return _orientationMask;
}
@end