Push notification when the application is completed

My application works great with push notifications if the application was in the background and / or if the application is in the foreground.

The problem is that the application is complete (which I force by double-clicking on the home button, find the application and swipe up the screen).

I am using ios 9 and swift 2.

In the application delegate, didFinishLaunchingWithOptions, I:

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) application.registerUserNotificationSettings(settings) application.registerForRemoteNotifications() 

Then:

 func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) { application.registerForRemoteNotifications() } 

Following didRegisterForRemoteNotificationsWithDeviceToken and didFailToRegisterForRemoteNotificationsWithError.

Then I use a relatively new method:

 func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {...} 

According to the documentation and the link, as against the old version of didReceiveRemoteNotification , this method is called if the application was interrupted (how to resist the call to will / did finishLaunchingWithOptions).

However, if it was pressed (which was received - I see it on the screen) and I launch the application after it is completed, this method does not seem to be called the code that processes push (just send a notification so that it is matched by the corresponding ViewController) not called out.

What am I missing? Is there an extra check I need to do in the didFinishLaunchingWithOptions file? Somewhere else?

+6
source share
1 answer

I managed to solve the problem of intercepting remote Push when the application was completed for ios 9.1 with the following, but it failed on 9.2 (accidental failure?):

Register for remote:

 if #available(iOS 9, *) { let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) // UIApplication.sharedApplication().registerUserNotificationSettings(settings) // // UIApplication.sharedApplication().registerForRemoteNotifications() application.registerUserNotificationSettings(settings) application.registerForRemoteNotifications() } else if #available(iOS 8.0, *){ register for 8... } else { //ios 7 register for 7... } if let _ = launchOptions { if let _ = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary { handleRemotePush() } else if let _ = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification { handleLocalNots() } else { handleElse() } } 
+2
source

All Articles