# ios

Moritz Lindner

11/13/2023, 10:16 AM
Hi, I recently started developing an app using KMM that targets ios and android. The app is supposed to write some state to a file and read it later. For this I wanted to use KStore and when this did not work I tried okio (In the end the problem I faced was the same as KStore is using okio). When I try to write to a file, I get an
Uncaught Kotlin exception: okio.IOException: Operation not permitted
exception. The exception will only occur on a real iOS device, in the simulator it will work just fine. I found 1 issue regarding this problem in [KStores GitHub Issues]( which basically says that it is an OKIO related issue. Does anyone know of a workaround, and if not, could you reference different libraries/ideas to implement file persistence in this context?🙂

Konstantin Tskhovrebov

11/13/2023, 10:42 AM
have you tried to get correct dir path on the iOS?
Copy code
private fun getCacheDirectoryPath(): Path {
    val cacheDir = NSSearchPathForDirectoriesInDomains(
    ).first() as String
    return "$cacheDir/cache".toPath()

Moritz Lindner

11/13/2023, 12:47 PM
Until now I was getting the
. I will it with the cache directory. Just for clarification. What does cache in this context mean? Will the content be deleted after the App is closed or the device is rebooted?
Using the CacheDir worked 🙂 Thx

Jeff Lockhart

11/13/2023, 2:37 PM
On iOS, apps only have access to the application sandbox, so there's no user home directory equivalent that's accessible. The cache directory can be cleared by the system on rare occasions. Check out this article which describes what your options are for directories that you can read and write.
👍 1


12/01/2023, 1:56 AM
Hi Guys. Author of KStore here 👋 Let me make this more clearer on the docs so that people won't run on to this issue. I wish apple make the simulator's security policies works the same way as on devices