Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果#可用(iOS 9,*)不工作_Ios_Swift_Ios8_Swift2_Ios9 - Fatal编程技术网

如果#可用(iOS 9,*)不工作

如果#可用(iOS 9,*)不工作,ios,swift,ios8,swift2,ios9,Ios,Swift,Ios8,Swift2,Ios9,我发现我的代码中有一行代码不喜欢在iOS8上运行,但有一种方法可以在iOS8上用不同的逻辑执行相同的任务,这与iOS9不同 我使用了if#available(iOS9,*)在iOS9上执行我需要的代码,在iOS8上执行我需要的代码。但是,在运行时,在对函数进行了几次调用之后,iOS9设备会运行它不应该运行的代码并崩溃。我是否错过了设置的步骤(如果可用)(iOS 9,*) 代码如下 if #available(iOS 9, *) { if(self.otherChats[loc].last

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

我使用了
if#available(iOS9,*)
在iOS9上执行我需要的代码,在iOS8上执行我需要的代码。但是,在运行时,在对函数进行了几次调用之后,iOS9设备会运行它不应该运行的代码并崩溃。我是否错过了设置
的步骤(如果可用)(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)
}

可用
检查应正常工作。由于要执行的代码在这两种情况下是相等的(除了
if
),问题很可能是
if
条件(
self.otherChats[loc].last?.timestamp!!=messageObj.timestamp!
)是
true
,而您认为应该是
false


尝试向两个可用的块添加日志,您很可能会看到第二个块(iOS 8块)从未在iOS 9设备上执行。

如果
(self.otherChats[loc].last?.timestamp!!=messageObj.timestamp!)
为真或假,它不应该超过
else
,因为
else
链接到
if#available(iOS 9,*){
@MarkMasterson,这正是我想说的。你确定这是在
#available
else块中吗?因为这两个块的结果是一样的。你把log/brakepoint放在那里了吗?如果是的话,那可能是个bug,最好通过向苹果报告。
   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)
    }