gpt4 book ai didi

swift - 错误 : no such module 'FirebaseInstanceID' on ios

转载 作者:行者123 更新时间:2023-12-04 12:20:25 27 4
gpt4 key购买 nike

我正在尝试运行我的代码并不断告诉我

error: no such module 'FirebaseInstanceID'
import FirebaseInstanceID
我在 AppDelegate.swift 中的代码
import UIKit
import Flutter

import Firebase
import FirebaseAuth
import UserNotifications
import FirebaseInstanceID

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let firebaseAuth = Auth.auth()
firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)

}
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let firebaseAuth = Auth.auth()
if (firebaseAuth.canHandleNotification(userInfo)){
print(userInfo)
return
}

}
}
我认为我的 pod 中缺少它,我不知道如何将它安装到我的 pod 文件中。

最佳答案

FirebaseInstanceID 现在已弃用,这就是出现此错误的原因。删除 import FirebaseInstanceID 来自您的 AppDelegate.swift 而是添加 import FirebaseMessaging 因为 FCM token 现在直接在 Messaging 实例上提供。现在替换的代码InstanceID didRegisterForRemoteNotificationsWithDeviceToken 有了这个

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
Messaging.messaging().token { (token, error) in
if let error = error {
print("Error fetching remote instance ID: \(error.localizedDescription)")
} else if let token = token {
print("Token is \(token)")
}
}
}

关于swift - 错误 : no such module 'FirebaseInstanceID' on ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67539357/

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