-[FBLPromise HTTPBody]:非初始启动时发送到实例 0x600001afa700 错误的无法识别的选择器。谷歌翻译 MLKit
我正在尝试将 Google MLKit Translate 添加到我的 SwiftUI 项目中。我已经通过 SPM 使用 firebase,并且仅在首次启动后才出现此错误: -[FBLPromise HTTPBody]: 无法识别的选择器发送到实例 0x600001afa700
这是我的代码:
App Delegate
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
}
然后我这样调用它:
if ModelManager.modelManager().isModelDownloaded(spanishModel) {
Translator.translator(options: englishSpanishTranslator).translate(buis.name!) { translatedText, error in
if error == nil {
if let translatedText = translatedText {
name = translatedText
}else {
print("error = \(error)")
}
}else {
print("error = \(error)")
}
}
}else {
print("error = Spanish not downloaded")
}
我还尝试过使用内置的 FirebaseMLKitDownload,但它没有翻译器。到底是怎么回事?
I am trying to add Google MLKit Translate into my SwiftUI Project. I am already using firebase via SPM and only after the initial launch get this error: -[FBLPromise HTTPBody]: unrecognized selector sent to instance 0x600001afa700
Here is my code:
App Delegate
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
}
Then I call it like so:
if ModelManager.modelManager().isModelDownloaded(spanishModel) {
Translator.translator(options: englishSpanishTranslator).translate(buis.name!) { translatedText, error in
if error == nil {
if let translatedText = translatedText {
name = translatedText
}else {
print("error = \(error)")
}
}else {
print("error = \(error)")
}
}
}else {
print("error = Spanish not downloaded")
}
I have also tried using the built in FirebaseMLKitDownload and that doesn't have translator. What is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这篇文章的作者可能找到了解决这个问题的解决方案(
我不知道如何找到解决方案,但是经过几个小时的调试后,我注意到当我使用Xcode中内置的依赖项管理器初始化firbase初始化项目时发生了问题,然后我尝试使用Cocoapods初始化Firestore。更具体地说,我要做的第一件事是使用此操作安装:
然后,我开始使用CocoApods,例如:
下一步,我尝试检查基本的Firestore操作数据以及运行应用程序时 - 我有类似的错误。在应用程序运行期间,这是一个例外。
我认为,有问题的事情可能是重复的,因为两次为该项目提供了壁炉(具有所有依赖性)。
因此,我删除了从Xcode Manager安装的依赖项。在我的
info.plist
中没有依赖关系:然后,从终端i删除
pods
目录,刚刚称为更新。重新安装了所有依赖项,并重新创建了工作空间。
现在,在这些步骤之后,一切都很好。
Probably an author of this post found solution of this problem (judging by the comment) but I decided to write this post because few hours ago during taking my first steps with Firebase I had the same error. I hope my post may be helpful for each other.
I had no idea how to find solution but after few hours of debugging I noticed that the problem occurs when I had initialized project with Firebase using dependency manager built-in in the Xcode and then I tried to initialize Firestore using CocoaPods. To be more specific, first thing I do was Firebase installation using this one:
Then, I started using CocoaPods like:
In the next step, I tried to check basic Firestore operations like creating collection and documents with data and when I run the app - I got similar error. It was an exception during app run.
I think in my case the problematic thing was possible duplicates because of supplying the project with a Firebase (with all dependencies) twice.
So, I removed dependency installed from the Xcode manager. In my
Info.plist
there is no dependencies:Then, from the terminal I removed
Pods
directory and just called an update.All dependencies were re-installed and workspace has been recreated.
Now, after these steps everything works fine.