菜鸟教程小白 发表于 2022-12-11 18:06:31

ios - 推送通知应用程序后台 iOS 9 swift


                                            <p><p>我有一个适用于 iOS 10 和 iOS 9 的应用,我必须管理远程推送通知:</p>

<p>对于 iOS 10,我使用 <code>UNUserNotificationCenter</code> 以这种方式管理它:</p>

<pre><code> @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,willPresent notification: UNNotification, withCompletionHandler   completionHandler: @escaping (_ options:   UNNotificationPresentationOptions) -&gt; Void) {
      print(&#34;Foreground push notification&#34;)


    }

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

       print(&#34;Background push notification&#34;)

   }
</code></pre>

<p>对于 iOS 9,我只能在应用程序处于前台时使用此方法管理到达的推送通知:</p>

<pre><code>func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: ) {

       print(&#34;arrived push notification in foreground for iOS 9&#34;)
    }
</code></pre>

<p>但是当应用程序在后台时,此方法不会执行,我无法管理新的推送通知。
你能帮帮我吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>Apple 对这些通知设置了限制...当应用程序处于后台时,不能执行应用程序的任何 block 或功能...例如,任何第三方警报应用程序都会根据通知触发警报,并且一旦点击通知应用程序启动并进入功能 didreceivenotification... 而 Android 可以显示占据整个屏幕以打盹或解除警报。当您在应用程序内部时,Apple 为您提供了您想做的所有功能,但在后台或应用程序被终止时,无法执行任何功能或 block 。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 推送通知应用程序后台 iOS 9 swift,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40713660/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40713660/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 推送通知应用程序后台 iOS 9 swift