-1

I had gone through many posts, bout couldn't get clarity on is there a way to get push notifications when app is quit.

I tried with content_available with (true/1) and Priority as High, I hear the notification sound but not notification badge or content on App. Any clue will be appreciated.

{ to=/topics/lshekhar,                                    
  content_available=1,                                  
  collapse_key=sample, 
  delay_while_idle=true, 
  delivery_receipt_requested=true,
  priority=10,  
  data={message={ "id" : "eARMS", 
                  "submitter" : "lshekhar", 
                   "topic" : "/topics/lshekhar" 
                }},  
  time_to_live=10000, 
  notification={"sound":"default"}, 
  message_id=m-3319428685310488470, 
  badge=12}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
leela
  • 62
  • 7

1 Answers1

1

This seems to be issue in iOS 10. This happens when your payload's body key has null or "" (empty string).

This can easily be reproduced with local notification as well. Ask your APNS payload creator to add non empty string to body and notification will show up with banner.

"alert": {
            "title": "Some title : ",
            "body": "Some body text"
}

This should solve your issue. Hope it helps

EDIT:

As OP has asked for the way to access notification payload when the app is quit and app receives APNS,I am updating the answer

You can access the APNS payload if the app happens to receive the APNS while its quit using AppDelegate's

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   if (launchOptions != nil) {
        NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (dictionary != nil) {
            /*it is an APNS launch
        }
    }

   ...
}

Hope it helps

Sandeep Bhandari
  • 19,999
  • 5
  • 45
  • 78
  • Thank you so much for your Answer. By clicking the notification it doesn't open the application. Also In didReceiveRemoteNotification method will do modify the Title and save the body content in SQL which will be used to display the list of notifications received. Any idea, which method it hits in case of application quit ? So that I can do customise the same and save in DB? – leela Jun 15 '17 at 10:25
  • I am able to get the badge now with below format. {to=/topics/lshekhar.earms, content_available=true, collapse_key=sample, delay_while_idle=true, delivery_receipt_requested=true, priority=high, time_to_live=10000, notification={"sound":"default","title":"Tool Connect", "body":message={ "id" : "eARMS", "submitter" : "lshekhar", "topic" : "/topics/lshekhar.earms", "requestname" : "RequestId - eARMS_2017-06-1515:24:20" }, "badge":"12"}, message_id=m-1317505031125464473} – leela Jun 15 '17 at 10:25
  • @leela : Glad that I could help :) If the application is quit and your app happen to receive the notification, if user taps on notification to open the app your app delegate's didFinishLaunch with options method's launch options dictionary will have notification dictionary. U can access it by using UIApplicationLaunchOptionsRemoteNotificationKey :) – Sandeep Bhandari Jun 15 '17 at 10:34
  • @leela : On the other hand if you are using iOS 10 notification you can always use willPresentNotification delegate to access notification :) Please consider accepting the answer if it helped you :) – Sandeep Bhandari Jun 15 '17 at 10:38