【问题标题】:Different code for different iOS version is still showing a warning [duplicate]不同iOS版本的不同代码仍然显示警告[重复]
【发布时间】:2015-09-25 13:12:28
【问题描述】:

自更新到 iOS 9.0 以来,我正在尝试清除我的应用程序的所有警告,并且我正在尝试这样做:

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0
// less than iOS 9.0
- (NSUInteger)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskPortrait;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}
#else
// iOS 9.0 or later
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskPortrait;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}
#endif

但我仍然收到所有警告,我做错了什么?

我发现此指令在 iOS 8.0 和 iOS 7.0 中无法正常工作。

- (UIInterfaceOrientationMask)supportedInterfaceOrientations

【问题讨论】:

    标签: ios objective-c ios9 xcode7


    【解决方案1】:

    我认为 - (NSUInteger)supportedInterfaceOrientations {} 在 iOS 9.0 中不起作用。

    所以,你必须使用 - (UIInterfaceOrientationMask)supportedInterfaceOrientations。它适用于所有 iOS 版本。

    不要检查 iOS 版本。仅使用
    - (UIInterfaceOrientationMask)支持所有 iOS 版本的InterfaceOrientations 方法。

    【讨论】:

      【解决方案2】:

      您的#if 代码和#else 代码是相同的。那么你期待什么?

      【讨论】:

      • 它们不相同。返回类型不同。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多