Reputation: 191
Can I get list of my app push notifications from native Notification Center app? When the my app starts, I want to show notifications which were received while my app is not running.
Upvotes: 0
Views: 2081
Reputation: 1375
Actually you can get list of notifications with iOS 10
For this you have method in UNUserNotificationCenter
// Notifications that have been delivered and remain in Notification Center.
open func getDeliveredNotifications(completionHandler: @escaping ([UNNotification]) -> Swift.Void)
And do it like this
UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { (notifications) in
// do what you whant with the notifications array
})
Upvotes: 3
Reputation: 9898
If you don't want to miss any notification.
You can use Pushkit silent push notification.
Once you receive pushkit payload and your app you can schedule local notification and also keep in NSUserDefault
.
Using silent push notification your app will be active in background even app is in terminated state. It will be active upto your local notification sound plays ( Max 30 seconds ). You can also keep data in SQLite
in that duration.
Once you open app from icon or from notification you can check your NSUserDefauls
or SQLite
and do further things.
Note - With normal push notification, your app would get active in background or terminated state, so you can not write any code to keep data within app which cam along with push notification
Reference - https://github.com/hasyapanchasara/PushKit_SilentPushNotification
Let me know if further clarification is required.
Upvotes: 1
Reputation: 50089
as said by Tian:
there is no api to get a list of notifications your app missed.
no way.
you only get the one the user clicked to launch your app.
Upvotes: 0
Reputation: 64
If you start your app from the icon, you can't get notifications
You can get one when you click the notification to start your app
Upvotes: 1