【问题标题】:Update deprecated Firebase functions in Swift更新 Swift 中已弃用的 Firebase 函数
【发布时间】:2020-10-12 16:01:36
【问题描述】:

我有这个代码来推送应用通知。 它运作良好,但我收到此警告: 'MessagingRemoteMessage' 已弃用:FCM 直接通道已弃用,请使用 APNs 进行下游消息处理。 而这个 'appData' 已弃用

我在 Google 上进行了研究,但没有找到任何解决此问题的方法。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        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 })
            // For iOS 10 data message (sent via FCM
            Messaging.messaging().delegate = self
        } else {
            let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
              application.registerUserNotificationSettings(settings)
        }
         
        application.registerForRemoteNotifications()
         
        FirebaseApp.configure()
        
        return true
    }
    
    // The callback to handle data message received via FCM for devices running iOS 10 or above.
    func applicationReceivedRemoteMessage(_ remoteMessage: MessagingRemoteMessage) {
        print(remoteMessage.appData)
    }

【问题讨论】:

标签: ios swift firebase firebase-cloud-messaging appdelegate


【解决方案1】:

问题是您是否只是发送显示/警报通知和后台通知?或者您是否使用直接渠道发送一些隐藏的数据消息以进行实时更新?

MessagingRemoteMessage 是通过直接通道发送和处理的数据消息对象。如果您只想推送通知,并且您似乎也没有在上面的代码中启用直接通道。您可以使用 Apple 的 API UNUserNotificationCenterDelegate 来处理警报消息或 AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler: 来处理后台通知。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 2013-09-01
    相关资源
    最近更新 更多