iOS 后台任务

首先开启后台任务技术图片

 

使用设置后台任务触发的时机

application.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { //这里写获取服务器数据的代码 completionHandler(.newData) //.newData .noData .failed }

 使用模拟器不会自动触发后台任务 需要手动点击 Debug -> Simulate Background Fetch 测试

相关文章