phrase / ios-sdk

Phrase Over the Air iOS SDK
https://phrase.com
Other
14 stars 3 forks source link

Swizzling not working #14

Closed irlennard closed 4 years ago

irlennard commented 4 years ago

I'm using the Phrase OTA SDK in my Swift app, and it appears that the swizzling is not working. NSLocalizedString() does not give me the updated translations, Phrase.shared.localizedString(forKey:) does however (I did not turn off swizzling). I'm using the latest SDK (2.1.0) with Xcode 11.4.1 and Swift 5.2.2.

winkelsdorf commented 4 years ago

@irlennard Thank you for your report!

When swizzling is enabled Phrase.shared.localizedString(forKey:) internally just forwards to Bundle.main.localizedString(forKey:) (as this method is swizzled).

Without seeing any code, I think you are probably running into a timing issue. The completion closure of updateTranslations() is a safe place to re-assign translations with NSLocalizedString() or Phrase.shared.localizedString(forKey:). Ensure dispatching to mainQueue first where needed.

Always a good hint: Please also try deleting the App from your Simulator or Device to see if the Bundle somehow got corrupted (not related to the OTA SDK).

Please let me know if this helps.

irlennard commented 4 years ago

Thanks for the tip. It was indeed just a timing issue as I was initialising the Phrase SDK just after creating the app's root view controller.

winkelsdorf commented 4 years ago

@irlennard You're weclome, glad I could help! 😊 No problem, asynchronous network communication is always a bit tricky to handle, especially when UI comes into play.