【发布时间】:2018-10-26 19:04:06
【问题描述】:
即使应用在后台,我的应用也希望每 5 秒更新一次有关用户位置的服务器。我为它实现了后台提取。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
application.setMinimumBackgroundFetchInterval(5.0)
return true
}
func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
completionHandler(UIBackgroundFetchResult.NewData)
UpdateData()
}
func UpdateData(){
print("UpdateData executes")
// function to update data when ever this method triggers
}
但问题是
- 我无法进入 performFetchWithCompletionHandler 方法,除非我点击 Debug>simulate background fetch
- 如何实现每 5 秒调用一次 performFetchWithCompletionHandler。
【问题讨论】:
-
你找到解决办法了吗?
标签: ios swift location background-fetch background-mode