I'm building push notifications into my iPhone app. I have the following in my AppDelegate
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
CCLogWarn(@"NOTIFICATION %@", userInfo);
completionHandler(UIBackgroundFetchResultNewData);
}
the CCLogWarn method uses cocoa lumberjack under the hood to send a log to my remote logging service (papertrail)
Here's what I'm experiencing:
- install the app on my device, the app is in the foreground
- trigger a notification from my server and I see the info show up in papertrail, everything's good!
- press the home button to move app to background, send another notification and see it pop up at the top of the screen. I tap it and the app launches and I see the info show up in papertrail, everything is still good!
- press the lock button on my phone and then send another notification. When I press the lock button again to turn the screen back on, I see the notification on the lock screen and I swipe it. The app launches but I don't see anything show up in papertrail. It seems
didReceiveRemoteNotificationwasn't called. - I then repeat steps 2 and 3 and I don't see anything in papertrail.
- I then force quit the app and relaunch it. I then try steps 2 and 3 and they work again (i.e. I see things appear in papertrail). But once I lock the phone again, it stops calling
didReceiveRemoteNotificationuntil I force quit and relaunch again.
I am sending content-available = 1 in my notifications. I have also enabled Background Mode in the apps capabilities and I have the following in my Info.plist
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
<string>fetch</string>
</array>
I also have logging for the launchOptions dictionary in didFinishLaunchingWithOptions but that isn't called when launching app from the lock screen either.
I ask this because I'd like to be go to a specific place in the app when the user gets a notification on their lock screen, I see plenty of other apps doing this and I imagine that they're relying on didReceiveRemoteNotification being called when the app is launched from the lock screen.