在 Swift 中更新已弃用的 Firebase 函数
Update deprecated Firebase functions in Swift
我有这个代码来推送应用程序通知。
它运作良好,但我收到此警告:
'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)
}
问题是您是否只是发送display/alert通知和后台通知?或者您是否使用直接通道发送一些隐藏的数据消息以进行实时更新?
MessagingRemoteMessage 是通过直接通道发送和处理的数据消息对象。如果您只想推送通知,而且您似乎也没有在上面的代码中启用直接渠道。您可以使用 Apple 的 API UNUserNotificationCenterDelegate 来处理警报消息或 AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:
来处理后台通知。
我有这个代码来推送应用程序通知。 它运作良好,但我收到此警告: '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)
}
问题是您是否只是发送display/alert通知和后台通知?或者您是否使用直接通道发送一些隐藏的数据消息以进行实时更新?
MessagingRemoteMessage 是通过直接通道发送和处理的数据消息对象。如果您只想推送通知,而且您似乎也没有在上面的代码中启用直接渠道。您可以使用 Apple 的 API UNUserNotificationCenterDelegate 来处理警报消息或 AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:
来处理后台通知。