ios10LocalNotification
ios10LocalNotification copied to clipboard
Notification is only received once
I moved the code that is included in the ViewController class of this ios10LocalNotification project into the App Delegate of my app, to allow it to automatically trigger when my app receives a remote notification.
When I first run the project, and send a notification to my app, the didReceiveRemoteNotification
method in my App Delegate runs, from which I call the triggerNotification()
method. This successfully creates the notification banner when my app is in the foreground, and also triggers the userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
delegate method in my App Delegate -- which returns the print statement of: Notification being triggered
.
Although, while still running the project, if I send a new notification to the app, the didReceiveRemoteNotification
method doesn't trigger, and therefore the triggerNotification()
also doesn't. But, the userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
does fire, so I still get the Notification being triggered
statement printed to my logs. So, my app isn't actually receiving any data from the remote notification or creating a push banner when new pushes are sent. It only works for the first push sent.
Here are my logs after sending the app 3 push notifications:
notification will be triggered in five seconds..Hold on tight
Notification being triggered
Notification being triggered
Notification being triggered
... as you can see, the notification will be triggered in five seconds..Hold on tight
only runs the first time, and not the other two.
What can I do to allow the triggerNotification()
method to run every time a new notification comes, and not just once following the startup of the app?
I have not mixed / tested local notification with push notification.So hard to tell what went wrong