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.
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
})
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
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.
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.
Related
I have an application running in the active state. Suddenly I receive a push notification, how does the application get notified about the notification and how does it handle?
You can read about this in apple documentation.
You need use didReceiveNotificationRequest:withContentHandler: in your AppDelegate.
After that you can show notification for user. If you want show notification on active state, you can show alert in application or use system banner.
I receive push notifications on certain events from a notification server we have.
I do want these notification alerts to appear when the app is not active in the background/foreground
I don't want the notification alert to appear when the app is active in the background (foreground not a problem since the notification doesn't show anyway). I want to show my own local notification, only.
Is there any way to do this from code? Basically I want to hide the remote push notification and instead show a local notification when my app is active.
P.S - The notification server sending silent notifications is not an option - the server does not know when our app is running/not running. There is no communication between the app and this server.
You can notify your application first and then show a local notification with that. To perform this you can simply send content-available notification from server. This makes your app notified and then you can decide on showing local notification or not.
I have an iOS app that needs to update its content while running in foreground automatically. My app does NOT need to update if in background.
There is a existing way to do so, which is APNS(Apple Push Notification Service).
Because I don't want users to see notification message while in background, using push notification without alert or message might be a solution.
However, if using APNS, iOS would ask users to confirm if they want to receive notifications by my app. I think that users may be confused when being asked by the OS since my app does not actually push notification to users.
The current method I use is keep pulling my API every 30 seconds to see if new content is available. This method would fail if there are too many users.
Is there any 3rd party push-notification-like service that provides notification while app runs in foreground only? (no need to get notification while in background)
You can use Silent notification for that, in this
In the WWDC 2013's "What's New with Multitasking" presentation, there is a section about Silent Push Notifications. if you send the APS payload with just the content-available set to 1, users will not be notified of the notification.
And the notification arrives in application:didReceiveRemoteNotification:fetchCompletionHandler:
Your payload is like
{
aps: {
content-available: 1,
sound: "default"
}
}
In case of push notification, it is necessary for user to accept push notification on application 1st run. You can set a silent push notification also and for this user will not get any alert of getting a notification during application run loop.
If you want to avoid push notification, then you can only set a NSTimer that you are doing already.
There can be a 3rd case, Application only sync with the server when it comes to foreground. And for this you can refer to my this post.
I'm writing an app that receives push notifications. When it gets one, and someone opens their phone through that notification, my application's delegate receives a application:didReceiveRemoteNotification: which comes with important notification data in the second argument.
However, if they get a push notification for another app, and open their phone through that, and then open my app, my apps notification is still queue in the pull-down notification center, and my app's delegate does not receive an application:didReceiveRemoteNotification: message with that push data until they tap that notification in the pull-down notification center. Ergo, I don't get the push data I want processed in my app regardless of how the user opens the app...
Is there a way I can get that notification in applicationDidBecomeActive: somehow?
Help appreciated. Thanks,
Nick
Unfortunately, it isn't possible.
As far as I know, there are only two ways for your app to learn about a push notification:
The user opens your app by tapping/swiping the notification
You app is open when the device receives the push notification
In the scenario where a user did not swipe a push notification before it disappeared, is there any way to retrieve the last one sent to the device for my app? I can go into the notification center and see the last few push notifications for my app there, is there any way I can retrieve the last one when my app opens?
There is no way to retrieve past push notifications.
Typically, this isn't needed. Once launched, your app can communicate with your server to see what's new.
If the app is launched from a notification, your app will receive the push notification passed in as an option with the key UIApplicationLaunchOptionsRemoteNotificationKey to the app delegate method application:didFinishLaunchingWithOptions.
If your app is running and in the foreground when the push notification arrives, the app delegate application:didReceiveRemoteNotification will be called
With iOS 7 and later, if the notification type is content-available and you have the Background App Refresh capability turned on (and the user has not disabled Background App Refresh), then an app in the background will also get application:didReceiveRemoteNotification