-[FBLPromise HTTPBody]:非初始启动时发送到实例 0x600001afa700 错误的无法识别的选择器。谷歌翻译 MLKit

发布于 2025-01-18 18:28:42 字数 1534 浏览 3 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷血 2025-01-25 18:28:42

这篇文章的作者可能找到了解决这个问题的解决方案(

我不知道如何找到解决方案,但是经过几个小时的调试后,我注意到当我使用Xcode中内置的依赖项管理器初始化firbase初始化项目时发生了问题,然后我尝试使用Cocoapods初始化Firestore。更具体地说,我要做的第一件事是使用此操作安装:

”

然后,我开始使用CocoApods,例如:

$ pod init
$ vim Podfile // adding 'firebase/firestore' dependency or specific line from https://github.com/firebase/firebase-ios-sdk
$ pod install
$ open <ProjectName>.xcworkspace

下一步,我尝试检查基本的Firestore操作数据以及运行应用程序时 - 我有类似的错误。在应用程序运行期间,这是一个例外。

我认为,有问题的事情可能是重复的,因为两次为该项目提供了壁炉(具有所有依赖性)。

因此,我删除了从Xcode Manager安装的依赖项。在我的info.plist中没有依赖关系:

”

然后,从终端i删除pods目录,刚刚称为更新。

$ rm -rf Pods
$ pod update

重新安装了所有依赖项,并重新创建了工作空间。
现在,在这些步骤之后,一切都很好。

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:

Xcode package dependencies manager

Then, I started using CocoaPods like:

$ pod init
$ vim Podfile // adding 'firebase/firestore' dependency or specific line from https://github.com/firebase/firebase-ios-sdk
$ pod install
$ open <ProjectName>.xcworkspace

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:

Xcode project Info.plist

Then, from the terminal I removed Pods directory and just called an update.

$ rm -rf Pods
$ pod update

All dependencies were re-installed and workspace has been recreated.
Now, after these steps everything works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文