简体   繁体   English

推送通知应用程序背景iOS 9 swift

[英]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: 我有一个适用于iOS 10和iOS 9的应用程序,我必须管理远程推送通知:

for iOS 10 I manage it in this way using UNUserNotificationCenter : 对于iOS 10,我使用UNUserNotificationCenter以这种方式进行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 : 对于iOS 9,我只能使用以下方法来管理到达的推送通知:

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已对这些通知设置了限制...当应用程序在后台时,该应用程序的任何块或功能都无法执行...例如,任何第三方警报应用程序都会根据通知触发警报,并在点击通知后立即点击该应用程序启动并进入功能didreceivenotification ...而Android可以显示占据整个屏幕的小睡或消除警报。 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. 当您位于应用程序内部时,Apple会为您提供世界上您想做的一切力量,但是当在后台或应用程序被杀死时,将无法执行任何功能或块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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