【发布时间】:2016-12-07 18:32:04
【问题描述】:
所以我一直试图弄清楚为什么 userInfo 没有显示我想要的数据。 当我打印 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)
}
}
【问题讨论】:
标签: swift xcode push-notification apple-push-notifications