即使应用程序在后台,我的应用程序也希望每 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 。