2/14/2024 0 Comments Kotlin multiplatform iosSweet! The keys and values are encrypted! Now you can read and write encrypted key-value data from common Kotlin code, maximizing code sharing. Once you have it all working, you can inspect the encrypted data storage on Android, by going to Android Studio, opening Device File Explorer, and navigating data → data → (Your Package Name) → shared_prefs → (Your Encrypted Settings Name) and you may see something like this: If you're using platform-specific DI / service locator solutions, they will also have options for providing named instances, like Dagger's support of the Javax annotation. Notice that the name of SharedSettingsHelper's constructor parameterencryptedSettings matches the name specified in our Koin setup it must be exact for Koin to know which one you want. Usually we'll use the builder, but the public constructor is really helpful here. Let's first take a look at the default non-encrypted AndroidSettings implementation. But thanks to the abstraction that Android has built into SharedPreferences and Multiplatform Settings' support for saving to the iOS keychain, our work is pretty easy. At first glance, it doesn't look like Multiplatform Settings offers any encrypted storage. There is a Settings interface that is implemented for Android, iOS, MacOS, and JVM platforms. Multiplatform Settings is a solid multiplatform key-value store, created by Touchlab's own Russell Wolf, used extensively at Touchlab, as well as in Jetbrains' KMM Production Sample. Today we'll go over how to store encrypted key-value data with KMP without having to reinvent the wheel. But if you're creating a mobile app using Kotlin Multiplatform, the KMP solution might not be as clear. This is a solved problem on Android with EncryptedSharedPreferences and iOS with the Keychain Services API. At some point you will probably need to store a user's auth token on the device, so they won't need to auth whenever they use your app.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |