IOS 定时任务

开启

 let timer = Timer.init(timeInterval: 15, target: self, selector: #selector(autoGet), userInfo: nil, repeats: true)
        
        RunLoop.main.add(timer, forMode: RunLoop.Mode.common)
        self.timer = timer

定时任务内容

   // 每15秒自动获取一次数据
    @objc func autoGet() {
        self.getAllExchangeSymbol()
        self.getAllNetWorkSymbol()
    }

结束任务

 self.timer?.invalidate()
        self.timer = nil

你可能感兴趣的:(IOS 定时任务)