My app want to update server about users location after every 5 seconds even if app is in background. I implemented Background fetch for it.
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
}
but the problem is
- I am unable to enter performFetchWithCompletionHandler method unless I click Debug>simulate background fetch
- How can I achieve to invoke performFetchWithCompletionHandler after every 5 seconds.