0

What is the way I can download all notification when my app is not running. My payload already having key content-available:1. But I am able to fetch data over which user is tapping. Is there any way by which I can count how many notification arrives when my app was inactive and set the badge number.

B25Dec
  • 2,301
  • 5
  • 31
  • 54

2 Answers2

0

You need to turn on push notifications in the projects target capabilities and then make your payload like this:

{
   "data": {
     "content-available": "1",
     "badge":"0",
     "sound":""
   },
   "where": {"test":"something_test"}
}

Adding the badge to 0 clears all remote push notifications, you can read more about Silent Push Here

Ladd.c
  • 973
  • 11
  • 11
  • Thanks for your suggestion. But when app is inactive, only control i got on push when user tap on it. Otherwise it just not came to app, neither i am able to set data nor i am able to set badge in to app. – B25Dec Jun 07 '18 at 04:49
  • You can check this https://stackoverflow.com/questions/36694963/what-is-silent-push-notification-when-does-the-device-receive-it – Ladd.c Jun 07 '18 at 21:31
  • I have checked mostly of the stackoverflow question before asking this one. None of them working so far. – B25Dec Jun 12 '18 at 05:52
0

I found a way by which we can download the push notification when app is killed. But badge counter, However is not possible to set at the time when app is killed. It can only be possible either you put a listener extension to your app, which will invoke your app from inactive state to background and download all. Or you can set badge via server, But at that time you have to maintain badge at server too. Below is the code to download the all push when your app is killed.

Whenever app is getting killed all notification came in to notification center, And there are two to open your app, i) via tapping over any push over notification center of device ii ) via tapping over app icon. Whichever way you choose to open the app you can write below code to download the all push when your app was inactive mode. In

didFinishLaunchingWithOptions

[[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray * _Nonnull notifications) { if (notifications.count > 0) { AudioServicesPlaySystemSound (1315); for (UNNotification* notification in withNotifications) { //NSLog(@"msg noti %@", notification.request); // [identifierArr addObject:notification.request.identifier]; NSLog(@"~~~>%@",notification.request.identifier); dispatch_async(dispatch_get_main_queue(), ^{ [self handlePushDatainKilledMode:notification.request.content.userInfo tappedByUser:false]; // the slow stuff to be done in the background }); } NSLog(@"~~~>Removing all notificaton"); [[UNUserNotificationCenter currentNotificationCenter]removeAllDeliveredNotifications]; } }];

Also important part is to remove once you download and save else when you open the app again and if you have handle any thing in another didreceive push it will replicate each push notification there too.

I am writing this solution perhaps it might help some one or save his time. thank you.

B25Dec
  • 2,301
  • 5
  • 31
  • 54