当我收到这样的远程通知时,我实现了一个打开 AlertView 的功能:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
var notifiAlert = UIAlertView()
var NotificationMessage : AnyObject? = userInfo["alert"]
notifiAlert.title = "TITLE"
notifiAlert.message = NotificationMessage as? String
notifiAlert.addButtonWithTitle("OK")
notifiAlert.show()
}
但 NotificationMessage 始终为零。
我的 json 有效负载如下所示:
{"aps":{"alert":"Testmessage","badge":"1"}}
我正在使用 Xcode 6、Swift 并且正在为 iOS8 开发。我现在搜索了几个小时,但没有找到任何有用的信息。通知工作得很好..如果我点击它,警报视图就会打开。我的问题是,我无法从 userInfo 中获取数据。