【问题标题】:SKStoreProductViewController crashes on iphone iOS 7 landscape appSKStoreProductViewController 在 iphone iOS 7 横向应用程序上崩溃
【发布时间】:2013-11-13 03:16:57
【问题描述】:

我有一个通用横向模式应用程序。 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”

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

【问题讨论】:

标签: iphone objective-c ipad ios7 landscape-portrait


【解决方案1】:

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

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

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

【讨论】:

  • SKStoreProductViewController 在支持方向的横向模式下的 iOS 11 / iOS 12 中无法正常工作:O
猜你喜欢
  • 1970-01-01
  • 2011-04-20
  • 1970-01-01
  • 2019-04-21
  • 2014-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多