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

时间:2013-11-01 20:32:40

标签: 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'

任何人都知道如何解决这个问题? 感谢

1 个答案:

答案 0 :(得分:9)

如果应用程序和ViewController没有通用的接口方向,您希望自动旋转返回NO。这是我的解决方案:

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

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