mlkit icon indicating copy to clipboard operation
mlkit copied to clipboard

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

Open Husseinhj opened this issue 2 years ago • 4 comments

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:

  • Set up an iOS share extension or action extension project.
  • Integrate the MLKit translator module into the extension.
  • Call the downloadModelIfNeeded method to download the translator model.
  • Attempt to utilize the translator module within the extension's service code.

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.

Husseinhj avatar Jun 05 '23 14:06 Husseinhj

Did you every find a solution to this @Husseinhj ?

morgz avatar Mar 21 '24 18:03 morgz

Did you every find a solution to this @Husseinhj ?

Nothing!

Husseinhj avatar Mar 21 '24 18:03 Husseinhj

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

morgz avatar Mar 21 '24 18:03 morgz

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.

Husseinhj avatar Mar 21 '24 18:03 Husseinhj