【问题标题】:UIApplicationLaunch by remoteNotification swift 3 not working由 remoteNotification swift 3 提供的 UIApplicationLaunch 不起作用
【发布时间】:2016-09-20 09:46:55
【问题描述】:

我在 swift 2.2 中工作正常,但是当我转换到 swift 3.0 时出现错误。

//If app open by notification
if launchOptions != nil
{
     NSLog("launch------ %@", launchOptions!)

     let  userInfo = launchOptions!(UIApplicationLaunchOptionsKey.remoteNotification) as NSDictionary
     if userInfo != nil
     {
         self.application(UIApplication.shared, didReceiveRemoteNotification: (userInfo)! as! [NSObject : AnyObject])
     }
}

类似错误

不能调用非函数类型'[NSObject : Any]'的值

提前致谢。

【问题讨论】:

    标签: swift push-notification swift3


    【解决方案1】:

    我终于修好了:-

    if launchOptions != nil
    {
         NSLog("launch------ %@", launchOptions!)
         let  userInfo = launchOptions![UIApplicationLaunchOptionsKey.remoteNotification] as! NSDictionary
         if userInfo != nil
         {
             self.application(UIApplication.shared, didReceiveRemoteNotification:(userInfo) as! [AnyHashable : Any] as! [String : AnyObject])
         }
    }
    

    【讨论】:

    • 我在使用这个时确实遇到了错误,您使用的是哪个 Xcode 版本?我正在使用 8 beta 3 并且似乎给出了一个错误:Ambiguous reference to member 'subscript'
    【解决方案2】:

    我的 Swift 3 解决方案。我必须使用一些强制转换才能获得价值:

        let key : AnyObject = UIApplicationLaunchOptionsKey.remoteNotification as AnyObject
        if let remoteNotification = launchOptions![key as! NSObject] as? [NSObject : AnyObject]{
            self.application(application: application, didReceiveRemoteNotification: remoteNotification)
        }
    

    【讨论】:

      猜你喜欢
      • 2016-05-17
      • 2023-03-15
      • 2017-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多