Swift 用户信息通知数据不可检索?

Swift 用户信息通知数据不可检索?,swift,xcode,push-notification,apple-push-notifications,Swift,Xcode,Push Notification,Apple Push Notifications,所以我一直在试图弄清楚为什么userInfo没有显示我想要的数据。 当我打印用户信息时,我得到以下信息: [AnyHashable("aps"): { alert = "test account \ni'm running late"; badge = 11; sound = "bingbong.aiff"; }] 但是,当我尝试执行userInfo[“alert”]时,它返回nil。我尝试了一切,包括userInfo[“aps”][“alert”],但仍然没有尝试。我

所以我一直在试图弄清楚为什么userInfo没有显示我想要的数据。 当我打印用户信息时,我得到以下信息:

[AnyHashable("aps"): {
    alert = "test account \ni'm running late";
    badge = 11;
    sound = "bingbong.aiff";
}]
但是,当我尝试执行
userInfo[“alert”]
时,它返回nil。我尝试了一切,包括
userInfo[“aps”][“alert”]
,但仍然没有尝试。我已经被困了好几个小时了。我希望有人能帮忙

以下是我的全部功能:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    //PFPush.handle(userInfo)
    if (userInfo["badge"] != nil) {
        let badgeNumber: Int = userInfo["badge"] as! Int
        application.applicationIconBadgeNumber = badgeNumber
    }
    if application.applicationState == .inactive {
        PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(inBackground: userInfo, block: nil)
    } else if application.applicationState == .active {
        let notificationManager = LNRNotificationManager()
        notificationManager.showNotification(title: "Test", body: "", onTap: { () -> Void in
            notificationManager.dismissActiveNotification(completion: { () -> Void in
                print("Notification dismissed")
            })
        })
        print(userInfo)
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "didRecieveNotificationWhileInApp"), object: nil)
    }
}

正如您在
userInfo
dump
badge
中看到的,它位于密钥
aps的字典中

if let aps = userInfo["aps"] as? [String:Any] {
  let badgeNumber = aps["badge"] as! Int
  application.applicationIconBadgeNumber = badgeNumber
}

哇,太谢谢你了。你不知道我花了多长时间才让它起作用,哈哈。