Reputation: 7425
I have properly set up my app for Remote Notifications
with the method
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)
and it processes it correctly now every time the app receives an Apple Push Notification
.
But my issue is that this method is being called in all instances now.
didFinishLaunchingWithOptions
does not seem to be called anymore? Or the launchOptions
is coming up empty?
Basically I used the didReceiveRemoteNotification
as a catch all to process any incoming notifications which is my intended purpose, but then when I click the notification itself, it fires the didReceiveRemoteNotification
again. Thus processing the notification twice, which I do not want.
So this is how I want my app to handle notifications:
didReceiveRemoteNotification
Upvotes: 1
Views: 328
Reputation: 12344
Apple does not allow what you want. Push notifications work in the following way
1) When the application is not running, and the user clicks a notification, the application is launched and the payload of the notification is loaded in the function didFinishLaunchingWithOptions.
2) When the application is running in background, and the user clicks a notification, the application becomes active and the function didReceiveRemoteNotification is called. Now this function contains the payload of the notification.
3) When the application is running and a push notification is called, the function didReceiveRemoteNotification is called and this function contains the payload of the notification.
4) When the app is running in background or inactive and notification is received, nothing can be done with the notifications until the user clicks the notification
Upvotes: 3