user2068793 user2068793 - 6 months ago 81
Objective-C Question

performFetchWithCompletionHandler never gets fired

1) My plist configuration to provide backgroundmode:

<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
</array>


2) In
didFinishLaunchingWithOptions
I have:

[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:1.0];


3) I declared the protocol
UIApplicationDelegate
in the delegate.

4) I implemented the following method, but it never gets fired. (It only works if I simulate the fetch with "XCode->Debug->Simulate Background Fetch".)

-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler


Why? Is this a DP5 beta error? Should I radar this?

Answer

I'm afraid this is hard to debug on a device because you're not guaranteed it is called in the amount of time you specify.

setMinimumBackgroundFetchInterval means that it is not called in an interval which is smaller than the value you specified. But there's no setMaximumBackgroundFetchInterval. So if iOS decides to call your app just once a day or even just once a week than it won't be called more often regardless your minimumBackgroundFetchInterval. AFAIK iOS decides when to call performFetchWithCompletionHandler measured by the pattern when and how often the users start's the app.