我正在使用swift和firebase.以前我使用以下方法来获取firebase令牌,然后我用它来存储到数据库中以发送通知.
InstanceID.instanceID().token()
现在这个方法显示为已弃用,因为我已经更新了我的firebase.
'token()' is deprecated: Use instanceIDWithHandler: instead.
我不知道如何使用instanceIDWithHandler我试过以下但不知道如何获得令牌.
func instanceID(handler: @escaping InstanceIDResultHandler){
    }
请帮忙.先感谢您.
最近在谷歌I/O活动中谷歌重新装修了Firebase并增加了许多新功能,并触及了其余的功能.我一直在尝试通过Firebase将iOS推送通知实现到我的应用程序中,通过最基本的级别,所以我创建了一个非常简单的应用程序除了接收远程推送通知之外什么都不做.
在Firebase内部,我上传了我的证书,在Xcode中,我的配置文件已添加到目标和项目中,而在Firebase中我已上传了正确的证书.下面是我的AppDelegate.swift文件中包含的代码,但因为我ViewController.swift的"空",我没有包含它.
虽然没有崩溃或运行时错误,但当我加载应用程序时,我接受通知.然后,我退出应用程序并关闭我的设备.在Firebase中,我将通知发送到正确的应用.几分钟后,在Firebase中,它说通知是"已完成".
但是,我从未收到过设备上的通知.因此,总之,我需要一个解决方案来发送Firebase deviceToken,然后使用"Firebase Notifications"发送推送通知消息.
我的代码或一般的任何帮助将不胜感激,我希望这有助于未来的观众.谢谢!我的代码在AppDelegate.swift:
import UIKit
import Firebase
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        FIRApp.configure()
        let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
        let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
        application.registerForRemoteNotifications()
        application.registerUserNotificationSettings(notificationSettings)
        return true
    }
    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        print("Device Token: \(deviceToken)")
    }
    func applicationWillResignActive(application: UIApplication) {
    }
    func applicationDidEnterBackground(application: UIApplication) { …我正在我的应用中实施Firebase推送通知.在一个教程中,我发现,我从一开始的令牌Messaging.messaging().fcmToken,并在此 SO问题,我发现这个方法:FIRInstanceID.instanceID().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 …