So, I have implemented background fetch in my app with performFetchWithCompletionHandler
and setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum
.
Requirement: In the handler, I am fetching remote data (1-2 second roundtrip) and comparing with existing data to see if there are changes. If changes exist, I display a local notification to the user.
Testing: I have modified the requirement to display local notifciation even if there is no change in data. ( So that I know background fetch works).
Issue: Background fetch does not work when NOTconnected to xcode and app running in debug or release mode.
Observations:
In Xcode, app debug mode using simulator, when I do "simulate background fetch" multiple times, the handler is called and local notifications are fired as expected. I stop running the app.
In Xcode, app debug mode and the iphone device connected to xcode, when I do "simulate background fetch" multiple times, the handler is called and local notifications are fired as expected. I stop running the app.
In Xcode, app release mode (with new scheme) using iphone device, when I run the app in xcode, the handler is called and local notifications are fired as expected first time. I stop running the app.
I also tried creating a ad-hoc DEBUG and RELEASE schemes and installing it on my device via itunes, so that I dont have to run the app via xcode. This doesnt seem to make any difference either. The notification didn't even fire once.
I do understand that background fetch is started based on app usage. I keep opening and closing the app and manually refreshing the data within the app to show activity. But I haven't seen any local notification firing at all.
For testing background fetch on my device without connecting xcode on debug or release modes, what should I do?