SKStoreProductViewController在iPhone iOS 7横屏应用程序中崩溃

4

我有一个通用的横屏应用程序。在iPad上,SKStoreProductViewController运行良好。但是,在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 上只能显示竖屏,但当我旋转手机时,它会崩溃。 我收到错误消息:

* Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation',reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

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


1
你看过这个网址吗?https://dev59.com/KGcs5IYBdhLWcg3w1XbZ - Daniel
1个回答

10

如果应用程序和ViewController没有共同的界面方向,您希望shouldAutorotate返回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 - sarra.srairi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接