1、报错提示
-
1.1 UIAlertController
- Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x1048f5600>) of style UIAlertControllerStyleActionSheet from
-
1.2 UIActivityViewController
- Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIActivityViewController (<UIActivityViewController: 0x103840000>). In its current trait environment, the modalPresentationStyle of a UIActivityViewController with this style is UIModalPresentationPopover.
2、解决办法
- 问题原因:这两个crash原因都是因为在ipad上进行UIAlertController和UIActivityViewController的使用的时候,都需要瞄点。
-
2.1 UIAlertController
// 兼容ipad
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
alert.popoverPresentationController.sourceView = sourceView;
alert.popoverPresentationController.sourceRect = sourceView.bounds;
alert.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
}
-
2.1 UIActivityViewController
// 兼容ipad
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
vc.popoverPresentationController.sourceView = self.view;
vc.popoverPresentationController.sourceRect = CGRectMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0, 1.0, 1.0);
vc.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
}
- 提示:其中vc就是对应的UIAlertController、UIActivityViewController的实例对象。