Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.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
Swift 使用计时器和Url下载web源不起作用_Swift_Macos_Cocoa - Fatal编程技术网

Swift 使用计时器和Url下载web源不起作用

Swift 使用计时器和Url下载web源不起作用,swift,macos,cocoa,Swift,Macos,Cocoa,我有一个定时器设置,它下载一个电话号码文本文件的来源。无论我将服务器上文本文件中的文本更改为什么,它始终保持相同的电话号码。如何让它下载最新的字符串 func scheduledTimerWithTimeInterval(){ // Scheduling timer to Call the function **Countdown** with the interval of 1 seconds timer = Timer.scheduledTimer(timeInterva

我有一个定时器设置,它下载一个电话号码文本文件的来源。无论我将服务器上文本文件中的文本更改为什么,它始终保持相同的电话号码。如何让它下载最新的字符串

  func scheduledTimerWithTimeInterval(){
    // Scheduling timer to Call the function **Countdown** with the interval of 1 seconds
    timer = Timer.scheduledTimer(timeInterval: 1/5, target: self, selector: #selector(self.updateCounting), userInfo: nil, repeats: true)
}
func updateCounting()
{

    view.window?.level = Int(CGShieldingWindowLevel()) + 1
    if (currentNumber == "")
    {
        resizeSmall()
    }
    else{
        resizeLarge()
    }
  //  let urls = URL(string : "http://www.xxxxxxxxx.net/CallerID/" + accountID + "/phone.txt")
    guard var urls = URL(string : "http://www.xxxxxxxxx.net/CallerID/" + accountID + "/phone.txt")
        else {
            print("Error:  doesn't seem to be a valid URL")
            return
    }
    do{
        var phonenumber = try String(contentsOf: urls, encoding: .ascii)
        if (phonenumber != "" && !NumberList.contains(phonenumber))
        {
            NumberList.append(phonenumber)
             print(phonenumber)
            TableView.reloadData()
    urls.removeAllCachedResourceValues()

        }

    }catch{

    }

}

它总是返回相同的电话号码,即使我经常更改它

很抱歉,在上传编解码器之前我意外地点击了save现在Idk what is up。我尝试清除url的缓存。每秒从远程url同步加载数据5次很可能不起作用。你真的在考虑这种轮询吗?问题是,我有一个windows应用程序,它使用WebClient做与此完全相同的事情,并且它工作正常。我也做了类似的速率。文本文件中有一个php文件,在接到电话时填充该文件,并用电话号码填充该文件,然后使用我的应用程序下载该电话号码。我在windows端没有任何错误