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

我有一个通用的横向模式应用程序. SKStoreProductViewController在iPad上运行良好.但在 iphone ios上崩溃7.甚至我将SKStoreProductViewController设置为在iPhone上的肖像上显示.

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

SKStoreProductViewController在iOS 7的iphone上显示,但是当我旋转手机时,它会崩溃.我收到错误消息说:

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

谁知道如何解决这个问题?
谢谢

解决方法

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

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

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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...