Reputation: 27
Push notifications are calling didReceiveRemoteNotification
when the app is running or when it's in background.
But if the user "kills" the app and I send a push notification, when the user taps on the notification, the app doesn't call didReceiveRemoteNotification
.
This is what I have:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)dict{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:dict[@"title"]
message:dict[@"description"]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"didReceiveRemoteNotification: %@", dict);}
Upvotes: 0
Views: 213
Reputation: 1569
According to UIApplicationDelegate protocol reference:
If the app is not running when a remote notification arrives, the method launches the app and provides the appropriate information in the launch options dictionary. The app does not call this method to handle that remote notification. Instead, your implementation of the application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method needs to get the remote notification payload data and respond appropriately.
When your app launches the applicationDidFinishLaunching will have data with any remote notifications received while the application was terminated. Use the code below when your application has finished launching.
if ([launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey])
{
[self application:application didReceiveRemoteNotification:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];
}
Upvotes: 3