条件绑定的初始化程序必须具有可选类型,而不是'字符串&#39 ;?

时间:2018-05-28 09:56:05

标签: swift firebase push-notification firebase-cloud-messaging

无法读取FCM通知用户数据,我正在尝试此 -

    let userInfo = response.notification.request.content.userInfo

             if let jsonResult = userInfo as? Dictionary<String, AnyObject> //**Getting error on this line**
{

             if let notifyType = 
              jsonResult["gcm.notification.notification_type"] as? String ?? "" 
              {

                print(notifyType)           

              }
            }

1 个答案:

答案 0 :(得分:3)

在你的代码中 替换:

  if let notifyType = 
      jsonResult["gcm.notification.notification_type"] as? String ?? "" 
      {

使用:

  if let notifyType = 
      jsonResult["gcm.notification.notification_type"] as? String {