iOS 11 应该由 App Delegate 方法或仅由 UNDelegate 方法处理推送通知
<p><p>我一直在寻找一个直接的答案,但还没有遇到,所以我假设在这里问我的问题。对于 iOS 10 后的应用,远程通知应该由 </p> 处理
<p>应用委托(delegate)方法:</p>
<pre><code> func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: , fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
}
</code></pre>
<p>或者,UNDelegate 方法:</p>
<pre><code> func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>TVOS 不支持 <code>UserNotificationsUI.framework</code>,因此如果您需要支持 TVOS,请坚持使用原始 <code>UIApplicationDelegate</code> 方法。</p>
<p>否则,<code>UNUserNotificationCenter</code> 是我的首选,如果您可以坚持使用 iOS10 后的支持,因为将来可能会弃用 <code>UIApplicationDelegate</code>。</code> p>
<p>如果您使用的是 WatchKit,则不推荐使用 <code>didReceiveRemoteNotification</code>,请勿使用它。来自 <a href="https://developer.apple.com/documentation/watchkit/wkextensiondelegate/1628170-didreceiveremotenotification#" rel="noreferrer noopener nofollow">documentation</a> :</p>
<blockquote>
<p>Instead of using this method, create a delegate object that adopts the
UNUserNotificationCenterDelegate protocol and implement the
userNotificationCenter:willPresentNotification:withCompletionHandler:
and
userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:
methods. Assign this object to the delegate property of the singleton
UNUserNotificationCenter object.</p>
</blockquote></p>
<p style="font-size: 20px;">关于iOS 11 应该由 App Delegate 方法或仅由 UNDelegate 方法处理推送通知,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/49858992/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/49858992/
</a>
</p>
页:
[1]