已有代码:
func handleRemoteNotification(remoteInfo:NSDictionary) { print("handleRemoteNotification remoteInfo=\(remoteInfo)") if UIApplication.sharedApplication().applicationState == UIApplicationState.Active { print("not handle remote notification for app is active running") } else { print("applicationState=\(UIApplication.sharedApplication().applicationState)") let messageDict = JSON(remoteInfo) SingletonConversationTVC().processSingleMessageDict(messageDict) } } |
中,想要把NSDictionary类型的remoteInfo,转换为(SwiftyJSON的)JSON
搜:
swift NSDictionary to SwiftyJSON
SwiftyJSON/README.md at master · SwiftyJSON/SwiftyJSON · GitHub
SwiftyJSON – code4swift|swift迷
swift – NSDictionary > JSON String using SwiftyJSON – Stack Overflow
好像是可以像上述代码中直接传入NSDictionary??
是的,代码中直接就可以了。
改为:
func handleRemoteNotification(remoteNotification:NSNotification) { print("handleRemoteNotification remoteNotification=\(remoteNotification)") if let userInfoDict = remoteNotification.object { print("userInfoDict=\(userInfoDict)") if UIApplication.sharedApplication().applicationState == UIApplicationState.Active { print("not handle remote notification for app is active running") } else { print("applicationState=\(UIApplication.sharedApplication().applicationState)") SingletonConversationTVC().updateAllConversation() } } } |
即可。
转载请注明:在路上 » [已解决]swift中把 NSDictionary转换为JSON