问题描述
我有这个代码来推送应用通知.它运行良好,但我收到此警告:不推荐使用MessagingRemoteMessage":不推荐使用 FCM 直接通道,请使用 APNs 进行下游消息处理.而这个'appData'已被弃用
I have this code to push app notifications.It works well but I get this warning:'MessagingRemoteMessage' is deprecated: FCM direct channel is deprecated, please use APNs for downstream message handling.and this one 'appData' is deprecated
我在 Google 上进行了研究,但没有找到任何可以解决此问题的方法.
I made a research on Google but didn't find anything to fix this.
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)
}
推荐答案
问题是您是否只是发送显示/警报通知和后台通知?或者您是否使用直接通道发送一些隐藏的数据消息以进行实时更新?
The question is whether you are simply sending display/alert notifications and background notifications? Or are you using direct channel to send some hidden data message for real time updates?
MessagingRemoteMessage 是通过直接通道发送和处理的数据消息对象.如果您只想推送通知,并且您似乎也没有在上面的代码中启用直接频道.您可以使用 Apple 的 API UNUserNotificationCenterDelegate 来处理警报消息或使用 AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:
来处理后台通知.
MessagingRemoteMessage is data message object sent and handled through direct channel. If you only want to push notifications, and you also don't seem to enable direct channel in your code above. You can use Apple's API UNUserNotificationCenterDelegate to handle alert message or AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:
to handle background notifications.
这篇关于在 Swift 中更新已弃用的 Firebase 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!