APNS - 致命错误:在展开Optional值时意外发现nil

时间:2017-05-01 04:32:56

标签: ios swift apple-push-notifications

当我收到Apns通知时,我点击它显示此错误的消息。
我不知道我有哪些可选值。

这样的消息:

application(_:didReceiveRemoteNotification:fetchCompletionHandler:):
[AnyHashable("aps"): {
alert = "test";
badge = 1;
sound = "chord.aiff";
}, AnyHashable("url"): web://title/123#456]


func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

let url:String = userInfo["url"] as! String

if url.hasPrefix("web://") {

    let link:String = url.replacingOccurrences(of: "web://", with: "")
    let params:[String] = link.components(separatedBy: "/")

    if params.count > 0 {

        if let topVC = UIApplication.topViewController() {

            switch params[0] {
            case "title":
                if params[1].isEmpty == false {
                    let vc:WebViewViewController = WebViewViewController()
                    vc.url = "http://192.168.144.1/title/\(params[1])"

                    topVC.show(vc, sender: self)
                }
            break
            default:
                print("123")
            break

            }

        }            
    }
}
}

topViewController,我把其他问题作为参考。
topViewController like this

0 个答案:

没有答案