0

This method is called when a push notification is received while the app is in background mode and the user clicks on notification. But I want to call a method when notification comes in background mode without the user to click on the notification.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    NSLog(@"%@",userInfo);
}
Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
priyanka gautam
  • 377
  • 4
  • 15
  • If you have the background processing entitlement for notifications enabled, and the APN dictionary contains the `content-available` key with a non-zero value, the delegate method should be called as soon as the APN is received, even before the user sees a banner (or alert) to tap on. – Avi Nov 04 '15 at 10:04
  • See [this answer](http://stackoverflow.com/a/31450953/594074)... – Baris Akar Nov 04 '15 at 13:31

1 Answers1

1

For this to happen you need to enable Background mode for remote notifications. You can find it Capabilities section of the project. Besides that your incoming Notification Payload should contain content-available:1 key-value pair. Then this method will be called immediately without user interaction.

Note: This works if the app is in Background or suspended state. If the app is completely killed or force quit by the user, it will not work.

harsha yarabarla
  • 506
  • 4
  • 11
  • I am enabled Background mode for remote notifications and Payload should contain content-available:1 key-value pair But not call my background method – priyanka gautam Nov 05 '15 at 07:13
  • @priyankagautam are you sure your APN contains { aps = { "content-available" : 1, sound : "" }; } in the similar fashion – harsha yarabarla Nov 05 '15 at 07:22