iosobjective-cuilocalnotificationuibackgroundtask

Execute background task after local notification was received in didReceiveLocalNotification:


Is it possible to execute a background task with [application beginBackgroundTaskWithName:@"LOG_STUFF" expirationHandler:^{}]; in the AppDelegate's method application:didReceiveLocalNotification:


Solution

  • If your application is in the foreground, yes!

    If your app is suspended (already in the background), the app has to be brought to the foreground for the "didReceiveLocalNotification:" method to fire and for you to be able to begin your background task.

    Check out Apple's documentation for "beginBackgroundTaskWithExpirationHandler:" method for more details on how to properly use this API.