【问题标题】:iOS Swift Getting Lazy Map Collection ValuesiOS Swift 获取惰性地图集合值
【发布时间】:2017-02-05 15:28:47
【问题描述】:

我正在尝试获得“警报”的价值,但运气不佳。

LazyMapCollection<Dictionary<AnyHashable, Any>, AnyHashable>(_base: [AnyHashable("google.c.a.e"): 1, AnyHashable("google.c.a.ts"): 1475009164, AnyHashable("google.c.a.udt"): 0, AnyHashable("gcm.n.e"): 1, AnyHashable("aps"): {
    alert = "test message";
}, AnyHashable("google.c.a.c_id"): 9039575328704479116, AnyHashable("gcm.message_id"): 0:1475009164740581%df6f7f01df6f7f01], _transform: (Function))

这是代码是一个使用,但它不能正常工作

if (userInfo["aps"] != nil) {
                    let msg = (userInfo["alert"] as? String)!
                    let alert1 = UIAlertController(title: "Notification", message: msg, preferredStyle: .alert)
                    alert1.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) -> Void in
                    }))
                    self.window?.rootViewController?.present(alert1, animated: true, completion: nil)
                    completionHandler(.newData)
                }

我正在尝试显示带有值警报消息的本地通知。任何想法,将不胜感激。谢谢

【问题讨论】:

  • “无法正常工作”是什么意思?它做了什么,你期望它做什么?这个LazyMapCollection 和它下面的代码有什么关系?
  • 我正在尝试在通知中显示“警报”的值,即“测试消息”。这行代码抛出异常 let msg = (userInfo["alert"] as?String)!

标签: swift dictionary collections lazy-evaluation


【解决方案1】:

这是我的工作解决方案

if (userInfo["aps"] != nil) {
                    if let notification = userInfo["aps"] as? NSDictionary,
                        let alert = notification["alert"] as? String {
                        let alert1 = UIAlertController(title: "Notification", message: alert, preferredStyle: .alert)
                        alert1.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) -> Void in
                        }))
                        self.window?.rootViewController?.present(alert1, animated: true, completion: nil)
                        completionHandler(.newData)

                    }
                }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-08
    • 2017-11-25
    • 1970-01-01
    • 2018-01-22
    • 2018-10-25
    • 2019-12-07
    • 2018-02-27
    • 1970-01-01
    相关资源
    最近更新 更多