For folks doing KMP w/ iOS and MVI, how do you han...
# multiplatform
k
For folks doing KMP w/ iOS and MVI, how do you handle iOS app state restoration (Android's savedstatehandle equivalent)? No luck searching this channel for "iOS app state restoration" which I thought was the right term for this...
m
I think iOS doesn’t have that problems, it doesn’t recreate apps, doesn’t kill them etc.
wait for somebody who is more familiar than I am to have a say but am pretty sure am right
k
If you’re using SwiftUi, this might be interesting for you: https://developer.apple.com/documentation/uikit/view_controllers/restoring_your_app_s_state_with_swiftui I’m almost sure I saw somewhere an article about the KMM version of the state save/restore mechanism, but I can’t find it right now. You can also take a look at the Decompose library which have StateKeeper mechanism
k
StateKeeper is only for Android AFAIK...that was the first thing I looked over... "Android Activity recreation" in the docs
a
iOS has the same concern indeed, but it is much less affecting. Because iOS is much less aggressive here. This is what I heard from various iOS folks. The StateKeeper comes from the Essenty library: https://github.com/arkivanov/Essenty And for now the state preservation really works only on Android. However I did a proof of concept a while ago, implemented @Parcelize compiler plugin for iOS. Here is my article: https://medium.com/bumble-tech/writing-kotlin-parcelize-compiler-plugin-for-ios-678d81eed27e Essenty library mentions this POC in its readme, seems like nobody interested in it. This is why it is still a POC and not something usable.
k
Yep, iOS is much less aggressive but it should still be handled for well behaving apps 🙂 I couldn't find anything in the moko libs either... You'd think someone would have hit it 🤔
a
Exactly, it is not something publicly available (at least not something I'm aware of either). Looks like not many people actually care about it. I ran a survey in Decompose repo, and nobody voted for this feature. https://github.com/arkivanov/Decompose/issues/157 I will think about resurrecting this idea.
k
I'm not sure people doing KMP are truly aware of this TBH. KMP people are mostly Android devs.... Not iOS devs... 🙂
k
For most of my comercial work I was android developer, Indeed you are right iOS is not so aggressive as IOS in terms saving restoring state. When I started to develop iOS I have few conversations with iOS developers and it looks no one cares about this. To be honest I was never able to reproduce that behaviour on iOS, and next issue is how to test save/restore code if you can’t enforce this system behaviour. On Android you can always use “don’t keep activities option”
k
https://developer.apple.com/documentation/uikit/uiscenedelegate/restoring_your_app_s_state "One technique is to suspend the sample app using the Home button, and then stop the debugger in Xcode. Launch the sample app again using Xcode, and UIKit initiates the state restoration process."
Sounds simple enough to me 🤔
a
Another way which I used for testing, is to add UIApplicationExitsOnSuspend flag: https://developer.apple.com/documentation/bundleresources/information_property_list/uiapplicationexitsonsuspen This is very simple to don't keep activities in Android.
k
Just to be clear I really would like to have possibility to do it properly without spending most of developing time on trying to test this. Last time when i tried that technique ( over 1,5 year ago ) It works randomly, In most cases application was launched without restoration. And even if app was launched in restoration mode, and something was wrong debugger was detached so you didn’t even have possibility to check logs 🙂
a
When I was working on the plugin mentioned above, I received feedback from different iOS folks, that it's really not so important and many devs just don't care about it. That's why I decided to suspend the development for now.
However feel free to file an issue, if someone is interested in that plugin. So we could decide what to do and track the progress. https://github.com/arkivanov/kotlin-parcelize-darwin
👍 1
m
@Arkadii Ivanov
Decompose
seems pretty interesting, having just glanced over it: is it something that would be beneficial for “vanilla” KMM implementations? I was just having some problems with my VM class (just a
class
in my shared module) being re-created every time I switch views: it’s just a basic class and as such a new instance was created every time I switched composable routes
a
@Matti MK Seems like your question is a bit unrelated to this thread. But anyway, I think Decompose should cover your case pretty well. You may also ask about your particular issue in #compose-desktop.
m
Good point 😅 figured it might be somewhat related as I’m talking about a “VM” shared between Android and iOS and as such some form of state restoration is required. I’ve not yet finished my investigations about what others have used to solve this problem, so I just figured out I’ll ask as these seemed like it might be something relevant. If I don’t find anything I’ll be sure to post a question on the proper channel 👍 Thanks for your response 🙇
👍 1
k
Should the tracking issue be on the Darwin parcelize plugin repo or the MVIKotlin or decompose repos?
Also curious what Touchlab does for iOS state restoration...sorry for the ping @kpgalligan 🙂
a
@kenkyee Better to file in the plugin's repo: https://github.com/arkivanov/kotlin-parcelize-darwin/issues
👍 1
@kenkyee Sorry my fault! Let's file an issue in https://github.com/arkivanov/Essenty, as it is the home of the
StateKeeper
👍 1
r
@kenkyee We generally haven't been handling this sort of state restoration on the iOS side, but are in the process of rethinking/codifying some of our architecture processes so this'll probably be a thing we look at
k
@russhwolf For me more important question is: Did You had any issues because of not handling that state restoration ?
k
Thanks Russell...would be curious what you come up with 🙂 Kamil: that's like saying if you have a flagship Android phone, it rarely happens because it has so much memory, so why bother doing it on Android 😉
r
yeah I'm not aware of us ever having issues reported about this, but it's not necessarily the sort of thing I would expect to make it up the feedback chain. Generally it's going to be a mild annoyance to some users who backgrounded the app in the middle of a flow, and took long enough to go back to it that now they have to start over. Certainly a real issue, but not one that necessarily gets reported and prioritized enough that I hear about it
a
Btw, the main purpose why I played with
kotlin-parcelize-darwin
plugin's implementation is to save/restore navigation back stacks. At that point I managed to get a working prototype of Decompose + TodoApp https://twitter.com/arkann1985/status/1379165652716564486?s=20
181 Views