gpt4 book ai didi

swift - FIRInstanceID.instanceID().token() 和 Messaging.messaging().fcmToken 有什么区别?

转载 作者:搜寻专家 更新时间:2023-10-31 08:04:11 25 4
gpt4 key购买 nike

我正在我的应用中实现 Firebase 推送通知。在一个教程中,我发现我从 Messaging.messaging().fcmTokenthis 中获取 token 所以问题我找到了这种方法:FIRInstanceID.instanceID().token()

它们有什么区别?我唯一的目标是能够向我的后端人员发送 token ,以便他们可以在数据库中识别我以获取推送通知。目前我生成 token 的代码是这样的:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

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()
let token = Messaging.messaging().fcmToken
setFCM(token: token ?? "UNDEFINED") //a function that saves it in user defaults.
print("FCM token: \(token ?? "")")
return true
}

最佳答案

调用它们中的任何一个都应该返回相同的注册 token 。

区别在于FIRInstanceID只有与注册 token 相关的方法(例如获取和删除 token ),而 Messaging(aka FIRMessaging -- naming changes )通常提供更多方法(例如订阅主题,向上游发送消息)。

关于swift - FIRInstanceID.instanceID().token() 和 Messaging.messaging().fcmToken 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44615817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com