簡體   English   中英

Swift字典,讀取鍵值-推送通知

[英]Swift dictionary, reading key values - push notifications

我正在嘗試在用戶收到推送通知時顯示警報。 我使用以下代碼顯示警報。 但是我不知道如何訪問推送通知的警報。

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

    var state: UIApplicationState = application.applicationState
    if state == UIApplicationState.Active {

        println(userInfo)
        println(userInfo["aps"])

        var alert2 = UIAlertController(title: "Push", message: "Received", preferredStyle: UIAlertControllerStyle.Alert)
        alert2.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in

        }))

        self.window?.rootViewController?.presentViewController(alert2, animated: true, completion: nil)

    }

}

我以為我只需要使用userInfo["alert"]但這只是零。 這就是我在日志中得到的。

[aps: {
    alert = "Jack sent you a message";
    badge = 1;
}]
Optional({
    alert = "Jack sent you a message";
    badge = 1;
})

因此,這只是我不知道如何使用快速字典。 抱歉,但誰能幫忙

我要做的就是使用(userInfo["aps"] as [NSObject: AnyObject])["alert"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM