我正在尝试将从远程通知传递的消息插入到我的应用程序内部的SQLite数据库的insert语句中。我想在我的AppDelegate里面的didReceiveRemoteNotification函数中做这个。远程通知以NSObject:Anyobject的形式出现,如下所示:
x = [google.c.a.e: I, aps: {
alert
= tyty;
} , gcm.n.e:
1, google.c.a.c_id: 705599158987573596, google.c.a.udt: e
id: google.c.a.
gcm.message_
1495589663]; y Y z
[google.c.a.e: I, aps: {
alert
= tyty;
} , gcm.n.e:
1, google.c.a.c_id: 705599158987573596, google.c.a.udt: e
id: google.c.a.
gcm.message_
1495589663]
我的问题是如何提取词典中突出显示的“警告”部分并将其转换为字符串对象,以便将其存储在我的SQLite数据库中?
答案 0 :(得分:0)
不确定X是字典还是数组,但如果字典比写这样
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
let x = userInfo["x"] as? [AnyHashable : Any]
let aps = x?["aps"] as? [AnyHashable : Any]
let alert = aps?["alert"] as? String
print(alert)
}