cannot force app to portrait-only in iOS9

2019-07-03 04:44发布

I need my app to only support portrait orientation. But after upgrading to iOS9, the orientation settings seem to have no effect. I have gone through this answer and here's my apps settings :

orientation settings

but still the app goes into landscape. what am I doing wrong?

3条回答
可以哭但决不认输i
2楼-- · 2019-07-03 05:14

Looks like I found the problem. When I viewed the source of my info.plist, this is what I found :

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

No Idea how the UISupportedInterfaceOrientations~ipad key came into being. It was not initially displayed when viewing as a property list, but started showing in property list after opened as source and saved.

Also there seems to be now way to set this in the general tab. Thanks to SamB and technerd for putting me on the right path.

PS: I am not sure if this is a bug or the intended behavior, so I welcome any insights on this.

查看更多
闹够了就滚
3楼-- · 2019-07-03 05:32

There is some sort of bug in iOS9. It completely overlooks the plist file orientation settings. So I had to add this code to each of my UIViewControllers to get portrait orientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationPortrait)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
    return UIInterfaceOrientationMaskPortrait;
}
查看更多
你好瞎i
4楼-- · 2019-07-03 05:35

Please check Info.plist for "Supported interface orientations". It must show Portrait for your requirement. Sometimes it is not updated as project settings in General Tab. If you find landscape orientation over here then remove it.

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>

enter image description here

查看更多
登录 后发表回答