ios - if#available(iOS 9, *) 不起作用

标签 ios swift ios8 swift2 ios9

我在我的代码中发现一行不喜欢在 iOS8 上运行,但有一种方法可以在 iOS8 上以不同的逻辑执行相同的任务,这与 iOS9 不同。

我已经使用 if#available(iOS 9, *) 在 iOS9 上执行我需要的代码,在 iOS8 上执行代码。然而,在运行时,在对该函数进行几次调用后,iOS9 设备会运行不应该运行的代码并崩溃。我是否错过了设置 if#available(iOS 9, *) 的步骤?

代码如下

if #available(iOS 9, *) {
    if(self.otherChats[loc].last?.timestamp! != messageObj.timestamp!){
        self.otherChats[loc].append(messageObj)
        self.Notfication.postNotificationName(_Chat.Notification.DidGetMessage, object: nil)
    }
} else {
    self.otherChats[loc].append(messageObj)
    self.Notfication.postNotificationName(_Chat.Notification.DidGetMessage, object: nil)
}

最佳答案

   let systemVersion = UIDevice.currentDevice().systemVersion        
    if((Double)(systemVersion) > 9.0)
    {
        if(self.otherChats[loc].last?.timestamp! != messageObj.timestamp!){
            self.otherChats[loc].append(messageObj)
            self.Notfication.postNotificationName(_Chat.Notification.DidGetMessage, object: nil)
        }
    }
    else
    {
        self.otherChats[loc].append(messageObj)
        self.Notfication.postNotificationName(_Chat.Notification.DidGetMessage, object: nil)
    }

关于ios - if#available(iOS 9, *) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34870116/

相关文章:

ios - AVAssetWriter 输出大文件(即使在应用压缩设置时)

ios - swift 3 : Use NSPredicate(format:) to filter objects by type/class

swift - 类型 'Any' 没有下标成员

ios - 本地通知不适用于某些用户 (iOS 8)

uiviewcontroller - iOS 8- viewController my_shouldAutopresent在PresentViewController时崩溃

自 SDK 8 更新以来,iOS 8 UIApplicationMain 崩溃

ios - 是否可以清除 Google Maps for iOS SDK 上的 map 图 block 缓存?

iOS 自定义流行过渡 - 就像在 snapchat 故事上向下滑动

ios - 字符 0 周围的 Alamofire 无效值

ios - ScrollView contentView 大小没有相应改变