googlesamples / mlkit

A collection of sample apps to demonstrate how to use Google's ML Kit APIs on Android and iOS
Apache License 2.0
3.45k stars 2.9k forks source link

[Bug report] Unable to Access MLKit Translator Model in iOS Share Extension #680

Open Husseinhj opened 1 year ago

Husseinhj commented 1 year ago

Description:

I am encountering an issue with the MLKit translator module when using it in iOS share extensions or action extensions. The problem arises from the inability to access the MLKit translator model that is downloaded by MLKit, as it is stored in the applicationSupportDirectory. Unfortunately, when attempting to utilize the MLKit translator module within an extension service, the extension is unable to access the applicationSupportDirectory path, resulting in a failure to find the necessary model files.

[0] (null)  "NSLocalizedDescription" : "Translation model files not found. Make sure to call downloadModelIfNeeded and if that fails, delete the models and retry." 

Steps to Reproduce:

Expected Behavior:

The share extension or action extension should be able to access and utilize the downloaded MLKit translator model located in the applicationSupportDirectory.

Actual Behavior:

The extension is unable to locate and access the MLKit translator model in the applicationSupportDirectory, leading to an error indicating that the model files are not found.

Proposed Solution:

I believe that providing a mechanism for sharing the MLKit translator model files between the main app and app extensions would be a beneficial feature. One possible solution could be to incorporate support for app groups, allowing the MLKit translator module to store the model files in a shared container accessible by both the main app and the app extension. This would ensure that the translator model can be successfully utilized within extension services.

Additional Information:

I have verified that the issue is specific to app extensions, as the MLKit translator module functions correctly when used within the main app. It seems that the limitation lies in the inability of the share extension or action extension to access the applicationSupportDirectory path where the model files are stored.

Thank you for your attention to this matter. I appreciate your support in resolving this issue or considering the suggested feature enhancement.

morgz commented 3 months ago

Did you every find a solution to this @Husseinhj ?

Husseinhj commented 3 months ago

Did you every find a solution to this @Husseinhj ?

Nothing!

morgz commented 3 months ago

until apple release some kind of Translation API I've fallen back to using google's cloud API. May try and figure this out at a later time but being lazy I wanted it to work out of the box

Husseinhj commented 3 months ago

until apple release some kind of Translation API I've fallen back to using google's cloud API. May try and figure this out at a later time but being lazy I wanted it to work out of the box

I'm also waiting for a public API from Apple. It's a really good idea. I need it only for offline purposes, but thanks for sharing the idea.