gpt4 book ai didi

apple-push-notifications - iOS 10 静默推送通知不会触发后台应用程序

转载 作者:行者123 更新时间:2023-12-03 22:46:00 26 4
gpt4 key购买 nike

我有一个应用程序,我试图在其中接收和处理 SILENT 推送通知。

我正在注册 APNs,如下所示:

UNUserNotificationCenter.currentNotificationCenter().delegate = self
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Badge, .Sound, .Alert]) {(granted, error) in
if granted {
application.registerForRemoteNotifications()
}
}

实现的:
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
// Handle notification
}

func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
// Handle notification
}

该应用程序有 UIBackgroundModes fetchremote-notification
APN 内容如下所示:
{
"aps":{
"content-available":1,
"badge":0
},
"action":"shareDelete",
"shareId":633
}

当应用在前台时, userNotificationCenter(centre:withCompletionHandler:willPresentNotification)收到通知时会触发,但当应用程序处于后台时,什么也不会发生。

我可以看到通过更改徽章编号收到了 APN,但在应用程序中没有触发任何内容。

我错过了什么?

(也在 Apple 开发论坛上问过)

最佳答案

方法

func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
// Handle notification
}

当用户点击通知或在 Apple Watch 上查看通知时调用:

Called to let your app know which action was selected by the user for a given notification.



您需要实现旧方法
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

}

关于apple-push-notifications - iOS 10 静默推送通知不会触发后台应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40406339/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com