我在我的代码中发现一行不喜欢在 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/