iphone - SKStoreProductViewController 在 iphone iOS 7 横向应用程序上崩溃

标签 iphone objective-c ipad ios7 landscape-portrait

我有一个通用横向模式应用程序。 SKStoreProductViewController 在 iPad 上工作正常。但在 iphone ios 7 上崩溃。甚至我将 SKStoreProductViewController 设置为在 iPhone 上以纵向显示。

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
   if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
       NSLog(@"iphone portrait");
       return UIInterfaceOrientationPortrait;
   }
   else
       return [super preferredInterfaceOrientationForPresentation];
}

SKStoreProductViewController 在 iphone iOS 7 上以纵向显示,但当我旋转手机时,它崩溃了。我收到错误消息说:

* 由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因:“支持的方向与应用程序没有共同的方向,shouldAutorotate 返回 YES”

有人知道如何解决这个问题吗?
谢谢

最佳答案

如果应用程序和 ViewController 没有共同的界面方向,您希望应该自动旋转以返回 NO。这是我的解决方案:

子类 SKStoreProductViewController 并使用以下内容覆盖 -shouldAutorotate:

- (BOOL)shouldAutorotate {
    UIInterfaceOrientationMask applicationSupportedOrientations = [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
    UIInterfaceOrientationMask viewControllerSupportedOrientations = [self supportedInterfaceOrientations];
    return viewControllerSupportedOrientations & applicationSupportedOrientations;
}

关于iphone - SKStoreProductViewController 在 iphone iOS 7 横向应用程序上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19734943/

相关文章:

iphone - iOS - 解析不同格式的日期

iphone - 如何将核心数据添加到选项卡栏应用程序

objective-c - iOS UI 外观错误

css3 视口(viewport)高度似乎在 ipad 上不起作用

iphone - 如何禁用 iOS 标签栏中的蓝色突出显示?

javascript - 如果在 touchstart 上删除触摸的子元素,则不会触发父级的“Touchend”事件

iphone - 将数据从 NSObject 发送到 UIViewController

iphone - 设置 UIDatePicker 日期时崩溃

iphone - 配置时立即使用属性还是使用临时变量?

ios - 在嵌入 UIView 的 UItableview 中的原型(prototype)单元中显示自定义 UIimageview