Reputation: 386
I am currently building an app that utilizes iOS 7's Silent Push Notifications to wake the app in background on request.
As I would do in -applicationDidEnterBackground:
I initiated a background task in -application:didReceiveRemoteNotification:fetchCompletionHandler:
which looks like this:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
self.taskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:self.taskId];
self.taskId = UIBackgroundTaskInvalid;
completionHandler(UIBackgroundFetchResultNewData);
}];
}
While the app successfully registers for remote notifications and -application:didReceiveRemoteNotification:fetchCompletionHandler:
is called on notification arrival, the app stays in background for just few seconds before returning to suspended state, much shorter than expected execution time given (when called in -applicationDidEnterBackground:
) which I believe is around 3 minutes.
Is this an expected behaviour? Or is it not possible using remote notifications?
Upvotes: 1
Views: 1125
Reputation: 48514
Have you properly configured the plist?
UIBackgroundModes
is subject to approvalFrom the documentation:
Background modes for apps:
UIBackgroundModes
value = remote-notification
The app wants to start downloading content when a push notification arrives. Use this notification to minimize the delay in showing content related to the push notification.
Upvotes: 0