在 UIPopoverPresentationController 中崩溃的应用,但没有明确的弹出窗口?

11 浏览
0 Comments

在 UIPopoverPresentationController 中崩溃的应用,但没有明确的弹出窗口?

我的应用程序(仅适用于iOS 8)因尝试进行IAP时发生崩溃而被拒绝。我已经尝试了几乎所有购买过程的变化,但无法重现崩溃。根据审核团队附上的崩溃日志,我发现最后一个异常回溯中有一个非常奇怪的堆栈跟踪。崩溃似乎涉及UIPopoverController,然而我的应用虽然是通用的,但没有在任何地方显式或隐式显示弹出视图。有人知道是什么可能触发了导致此崩溃的活动吗?为什么我的应用在审核团队查看时会显示弹出视图?

0
0 Comments

问题描述:在UIPopoverPresentationController中发生应用程序崩溃,但没有明确的弹出窗口。

问题原因:最可能是在iPad上发生的ActionSheet崩溃。

解决方法:您应该添加一个if条件,如下所示:

if let popoverController = alertVC.popoverPresentationController {

popoverController.sourceView = self.view

popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)

popoverController.permittedArrowDirections = []

}

0
0 Comments

该问题的出现原因是在iOS 9+版本中,在UIPopoverPresentationController presentationTransitionWillBegin方法中发生了崩溃,而崩溃的原因是sourceView属性为nil

解决方法是确保sourceView属性不为nil,可以通过以下方式实现:

UIViewController *vc = <#instance#>.
vc.modalPresentationStyle = UIModalPresentationPopover;
vc.popoverPresentationController.delegate = self;
vc.popoverPresentationController.sourceView = sourceView; // <--- 这里一定不能为nil.
vc.popoverPresentationController.sourceRect = sourceView.bounds;
[self presentViewController:vc animated:YES completion:nil];

0
0 Comments

这个问题的原因是在使用UIAlertController时,如果使用ActionSheet样式,iPhone上可以正常显示,但在iPad上需要设置sourceView,否则会导致应用崩溃。

解决方法是在iPad上设置sourceView,并且可以在iPhone上也设置,不会有任何问题。尽管问题的位置没有明确的提示,但可以通过检查代码来找到问题所在。

参考链接:https://stackoverflow.com/a/24233937/285694

0