【问题标题】:Value of type 'Messaging' has no member 'remoteMessageDelegate''Messaging' 类型的值没有成员 'remoteMessageDelegate'
【发布时间】:2018-05-27 10:47:39
【问题描述】:

当我更新 firebase pod 时出现以下错误:

'Messaging' 类型的值没有成员 'remoteMessageDelegate'

 //notification

    if #available(iOS 10.0, *) {
        let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_,_ in })

        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
        // For iOS 10 data message (sent via FCM)
        Messaging.messaging().remoteMessageDelegate = self as? MessagingDelegate

    }

我该如何解决这个问题?

【问题讨论】:

    标签: swift firebase


    【解决方案1】:
    if #available(iOS 10.0, *) {
    // For iOS 10 display notification (sent via APNS)
     UNUserNotificationCenter.current().delegate = self
    
     let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
      UNUserNotificationCenter.current().requestAuthorization(
    options: authOptions,
    completionHandler: {_, _ in })
    } else {
      let settings: UIUserNotificationSettings =
     UIUserNotificationSettings(types: [.alert, .badge, .sound], 
    categories: nil)
    application.registerUserNotificationSettings(settings)
    }
    
    application.registerForRemoteNotifications()
    

    https://github.com/firebase/quickstart-ios/blob/dc2cd2db6e82e5c475fa3f0efe75df8b54f04544/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55

    【讨论】:

    • 答案不正确。 Messaging.messaging().remoteMessageDelegate 已移至 Messaging.messaging().delegate。上面的代码 sn-p 错过了原始问题的实际修复行。
    猜你喜欢
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2018-01-15
    相关资源
    最近更新 更多