Reputation: 1950
I want to receive a single remote notification in iOS. When my server sent me multiple notifications and my application is closed, my notification page or the lock screen will contain all of notifications sent. Instead of that, i want just to receive on single notification which contains the last message only. I know it is doable since Whatsapp is already doing that when receiving a call and then update the notification to a missed call.
How could i accomplish that from server side? is there a notification ID that i could use to send it and be the same as the previous notification ID sent? or how could that be done?
Upvotes: 0
Views: 123
Reputation: 2613
There are two ways:
Send an notification with a payload that contains only badge: 0
and then send your notification. This should clear any previous notification that was sent.
You can enable multi-tasking features in your app and use the property UIRemoteNotificationTypeNewsstandContentAvailability
for registerForRemoteNotificationTypes
. Then, in (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
, you can set the badge count to 0 and then 1 to keep the last notification. You can read more about this here.
Upvotes: 0