【发布时间】:2018-06-22 22:40:41
【问题描述】:
如何读取“magazin”的值?
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let action = response.actionIdentifier
let request = response.notification.request
let userInfo = request.content.userInfo
if action == "open.magazin" {
var str: String?
let magazin = userInfo["magazin"]
print("MAGAZYN : \(magazin)")
}
completionHandler()
}
函数返回值:
MAGAZYN : Optional({"pages":100,"size":"50 MB","productId":"com.sad","purchased":false,"coverImageURL":"","cat":3,"itemPrice":"4,99","fileURL":"","id":5,"title":"test","demoStartPage":0,"desc":""})
【问题讨论】:
-
这是一个 JSON
String- 很多关于在 Swift 中读取 JSON 的示例,包括Codable和SwiftyJSON -
我尝试使用 swifty json 但它不起作用。
-
我无法处理此消息:“无法转换 'Any?' 类型的值?到预期的参数类型“数据”“
-
if let magazin = userInfo["magazin"] as? String { ... }
标签: swift xcode push-notification