gpt4 book ai didi

ios - 为什么我无法在 iOS 10 中处理收到的推送通知?

转载 作者:行者123 更新时间:2023-11-28 12:35:19 24 4
gpt4 key购买 nike

我已经导入了

import UserNotifications

和连接的代表:

UNUserNotificationCenterDelegate

并将委托(delegate)设置为自己:

UNUserNotificationCenter.currentNotificationCenter().delegate = self
FIRMessaging.messaging().remoteMessageDelegate = self

最后我有这些功能:

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
//Handle the notification
print("User Info = ",notification.request.content.userInfo)
completionHandler([.Alert, .Badge, .Sound])
}

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
//Handle the notification
print("User Info = ",response.notification.request.content.userInfo)
completionHandler()
}

但是当我在真实设备上和后台模式下测试时,我的日志上没有任何打印。

问题是什么?

internal func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print(userInfo)

// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")

// Print full message.
print(userInfo)
}

最佳答案

请尝试使用以下代码。您只需要保存数据。

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> ())
{
let info : NSDictionary! = userInfo as! NSDictionary

if info != nil
{
let aps = info["aps"] as? NSDictionary
UserDefaults.standard.set(aps, forKey: "aps")
}
}

并在您想使用的地方使用用户默认值。

关于ios - 为什么我无法在 iOS 10 中处理收到的推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41038791/

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