我尝试在里面用JSON发出接收通知。所以我在AppDelegate.swift里面编码。 我将NSObject转换为NSDictionary时遇到了问题。
这是我的代码:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { PFPush.handlePush(userInfo)
if application.applicationState == UIApplicationState.Active {
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
let msg = userInfo["test"] as? NSObject
print(userInfo)
if msg == nil{
let dict = msg as! Dictionary<String, Dictionary<String, Array<Dictionary<String, AnyObject>>>>
let tests = dict["test"]!["test"]!
for test in tets {
let header : AnyObject? = test["message"]
let body : AnyObject? = test["aps"]
let url : AnyObject? = test["link"]
print("test ID: \(header)")
print("test Name: \(body)")
print("test Needs Password: \(url)")
}
}
}
有2个问题: 1.我已经收到JSON数据作为对象 让msg = userInfo [&#34; test&#34;]为? NSObject的
Printing description of userInfo:
▿ 3 elements
▿ [0] : 2 elements
- .0 : message
- .1 : test iOS
▿ [1] : 2 elements
- .0 : aps
- .1 : 0 elements
▿ [2] : 2 elements
- .0 : link
- .1 :
但我的消息是零。所以如果msg == nil
,我必须继续执行此代码