I have the following code in my AppDelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
return true
}
func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
completionHandler(UIBackgroundFetchResult.NewData)
getData()
}
func getData(){
// function that gets certain data from the server and notifies the
// user of the info fetched
}
I am facing two problems here:
the first problem is that the background fetch is never executed unless I click on "Debug>simulate background fetch". i waited for it indefinitely and it was never called on its own.
The second problem is that when i click on simulate background fetch while my app is still open, the simulator exists the app and then performs the background fetch, even though the background fetch should still work even while the application is running and without closing it.
Am I missing any code related to background fetch ? Or is there any wrong code ? This is the only code I have written related directly to background fetch other than adding background fetch to the capabilities.