2013-11-01 82 views
4

我有一個通用的橫向模式的應用程序。 SKStoreProductViewController在iPad上正常工作。但iPhone ios 7崩潰。即使我將SKStoreProductViewController設置爲在iPhone上以縱向顯示。SKStoreProductViewController在iPhone上崩潰iOS 7的景觀應用程序

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

SKStoreProductViewController在iPhone iOS 7上的肖像上顯示,但是當我旋轉手機時,它崩潰了。我收到錯誤消息稱:

*終止應用程序由於未捕獲的異常「UIApplicationInvalidInterfaceOrientation」,理由是:「支持的方向與應用程序中沒有共同的方向,並shouldAutorotate將返回YES」

任何人知道如何解決問題?
謝謝

+1

你看看@ http://stackoverflow.com/questions/12540597/supported-orientations-has-no-共同的方向與應用程序和肩膀? – Daniel

回答

7

如果應用程序和ViewController沒有公共的接口方向,您應該自動旋轉以返回NO。這裏是我的解決方案:

子類SKStoreProductViewController並用以下覆蓋-shouldAutorotate:

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

B R I L L I A N N T!謝謝 – SpaceDog