我已经检查了这个问题的其他解决方案,没有一个对我有用。
如果我尝试在我的物理iPhone上验证GKLocalPlayer(不是模拟器;这适用于模拟器),我会收到以下错误:
Terminating app due to uncaught exception
'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has
no common orientation with the application, and shouldAutorotate is returning YES'
*** First throw call stack:
(0x373463e7 0x33d7e963 0x37346307 0x3815b857 0x382fff21 0x381dfcdd
0x381def6b 0x37349ad4 0x372a128f 0x382fd0f3 0x32acce01 0x30a19793
0x30a195db 0x30a1ce45 0x3731a1b1 0x3728d23d 0x3728d0c9 0x315d733b
0x38147291 0x101a73 0x1019d0)
我尝试将以下代码添加到视图控制器中,但没有任何更改:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
这个应用程序只能在横向上运行,我可以确认它只在我尝试通过Game Center验证玩家时才会发生。如果我把这条线拿出来,就没有问题了。
修改
为了澄清,当以下代码运行时会发生这种情况:
- (void)GKLogin
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated)
{
NSLog(@"Authenticated");
}
else
{
NSLog(@"Not Authenticated");
}
}];
}
答案 0 :(得分:2)
在应用程序委托中尝试此操作
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return (NSUInteger)[application supportedInterfaceOrientationsForWindow:window] | (1<<UIInterfaceOrientationPortrait);
}