crowdin/mobile-sdk-ios

Crash on Apple TV device

dannyhuggins opened this issue · 13 comments

Describe the bug
I am getting an app crash when using the SDK on a physical Apple TV device. I get the following error when the SDK is attempting to create the CrowdinFolder for the translation files:

Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=513 "You don't have permission to save the file "Crowdin" in the folder ".Crowdin"."

Note that this does not happen on the Apple TV simulator in Xcode, only a physical device.

To Reproduce
Steps to reproduce the behavior:

  1. Build to a physical Apple TV device
  2. The app crashes after starting the CrowdinSDK

Expected behavior
My understanding is that storing data on an Apple TV is not available outside of the cache directory, and when the SDK attempts to create a folder in the documents directory, the FileManager throws an exception.

Screenshots
Screen Shot 2022-02-22 at 6 49 22 PM

Smartphone (please complete the following information):

  • Device: Apple TV 4K (2nd generation)
  • OS: tvOS 15.3

Additional context
I was able to avoid the crash by changing DocumentsFolder.documentsPath from:
static let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
to:
static let documentsPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]
but I am not aware if this will have any performance implications.

is there a timeline for a bug fix for this? thanks in advance!

@dannyhuggins Thank you for your report! Is it possible to reproduce on a simulator device or only on a real one?

@serhii-londar unfortunately it's only possible to reproduce on a real device. The documents directory isn't accessible on real devices, so I'm not sure why Apple lets you access it on a tvOS simulator.

I experimented the documentsPath by pointing it to the .cacheDirectory instead of the .documentDirectory. Since the cache directory can be purged by the device, I tested what happens if the cache is deleted. It appears that the SDK will reconstruct the cache, but the en.plist file that previously contained the translations is now empty and I can no longer user OTA translations. I was unable to repopulate the .plist via restarting the app. It seems the only way to refresh the OTA translations in the app to push a release with new translations.

I think it makes sense for iOS to continue using the documents directory to avoid file purges, but tvOS will likely need some additional caching functionality since that's the only directory available for file storage on AppleTV.

Hi there! Checking everything from our side

@dannyhuggins Hi, can you please test whether changes from #180 request fixed that crash?

hey @serhii-londar I will take a look, thanks!

@dannyhuggins Did you have a chance to try the changes?

@serhii-londar We are no longer seeing a crash with this fix! However, our team noticed that if the tvOS cache is cleared, we are not seeing Crowdin re-retrieve OTA translations and instead falls back to the bundled translations. Our guess is it has something to do with ETagStorage using UserDefaults but we aren’t sure.

@dannyhuggins Thank you for checking it! Can you please send what path is used? Caches or Application Support?

it's using the Application Support folder, at least on the simulator. Having an issue with my AppleTV at the moment

Thank you, I will continue work on support.

@dannyhuggins Hi. Can you try to use changes #177 branch? The issue with downloading localization after the cache is cleared should be fixed.