我正在尝试将 Google MLKit Translate 添加到我的 SwiftUI 项目中。我已经通过 SPM 使用 firebase,并且仅在首次启动后才出现此错误:-[FBLPromise HTTPBody]: unrecognized selector sent to instance 0x600001afa700
这是我的代码:
应用程序委托
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
FirebaseApp.configure()
...
let spanishRemoteTranslator = TranslateRemoteModel.translateRemoteModel(language: .spanish)
if ModelManager.modelManager().isModelDownloaded(spanishRemoteTranslator) {
print("Spanish Translator Downloaded")
}else {
print("Downloading Spanish Translator")
ModelManager.modelManager().download(spanishRemoteTranslator, conditions: ModelDownloadConditions(allowsCellularAccess: true, allowsBackgroundDownloading: true))
}
return true
}
Run Code Online (Sandbox Code Playgroud)
然后我这样称呼它:
if ModelManager.modelManager().isModelDownloaded(spanishModel) {
Translator.translator(options: englishSpanishTranslator).translate(buis.name!) { translatedText, error in
if error == nil {
if let translatedText = translatedText …Run Code Online (Sandbox Code Playgroud)