简体   繁体   中英

push notification app background iOS 9 swift

I have an app that is for both iOS 10 and iOS 9 and I have to manage the remote push notification:

for iOS 10 I manage it in this way using UNUserNotificationCenter :

 @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,  willPresent notification: UNNotification, withCompletionHandler   completionHandler: @escaping (_ options:   UNNotificationPresentationOptions) -> Void) {
        print("Foreground push notification")


    }

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

       print("Background push notification")

   }

For iOS 9 I'm able to manage arrived push notification only when app is in foreground using this method :

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {

       print("arrived push notification in foreground for iOS 9")
    }

but when app is in background this method isn't execute and I can't manage the new push notification. Can you help me?

Apple has set restrictions to these notifications... No block or function of an application can be executed when the application is in background... For example any third party alarm application triggers the alarm based on notification and once tapped on the notification the application is started and enters the function didreceivenotification... Whereas Android can display occupy the entire screen to snooze or dismiss the alarm. Apple gives you all the power in the world u want to do when you are inside of your application, but when in background or application killed no functions or block can be executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM