Is there any library or best practice how to using...
# compose
j
Is there any library or best practice how to using equivalent of Android Intents but for iOS and other platforms? In my case I want to handle deeplinks, regular urls and also sharing data with other apps, as well as navigate to other apps. My first case is to navigate to another native app if its installed, and if not open AppStore/Google Play if it exists and if not open url as fallback. In general looking for something like LocalUriHandler, but LocalIntentHandler thingy to be able to do multi platform actions agnostic. I dont mind fix actual/expect if needed, but would be nice as much as possible using something agnostic. For Android using rememberActivityResult thing with contracts, maybe something similar approach also working on iOS and other platforms, not sure? And it also sadly need to support runtime permissions, as some things requires so 😄
m
I haven’t seen anything, and given that iOS has a completely different paradigm for how it handles it’s navigation stack (when compared to android), it’s not surprising. I would think you might have to roll your own here. Personally, i’d just write the UI controllers in the respective platform and use compose for the view layer.
And this is basically dynamic links:
Copy code
My first case is to navigate to another native app if its installed, and if not open AppStore/Google Play if it exists and if not open url as fallback.
There’s several products out there to handle this, and i’m not going to vouch for one over the other, and I know that Firebase links is sunsetting sometime next year, so that is not really an option.
j
So no easy one liner in iOS as in Android for that? 😏 I have my own navigation controller so I guess can inject into that.
m
I’m sure there’s people with a lot more knowledge than me on this topic, but I do know there’s huge navigation paradigm differences between android and ios. Even on android, when mixing compose and xml base navigation controllers, the navigation can get very hairy.
c
Navigate to another native app if it is installed
Even on Android, this is not a one-liner if I understand your requirement correctly. • First, you open an activity, not an app. • If you own the other app, then things are probably fine. If not, you'll need to go for the
queries
element in the Manifest and you'll be subjected to PlayStore policies since you are using some specific PackageManager APIs. • You might instead use a try-catch (not sure if any restrictions have appeared around that). On iOS I think this might not even be possible. As in, the generic intent mechanism doesn't exist on iOS. You probably need to know that another app ins installed and you need to know the format that it expects data in. (Not an expert, just thinking out aloud based on what I gathered from discussions here and there).
All of that to point out that could end up with more effort and brittle codebase if you try to unify everything with KMP. The power of KMP is it allows you to share for things that are more suitable to share; and it allows you to use native where that makes more sense. I feel this specific usecase you have is a textbook example of something that is better to be done natively.
j
@curioustechizen Yeah sorry I meant oneliner for the case of
My first case is to navigate to another native app if its installed, and if not open AppStore/Google Play if it exists and if not open url as fallback
🙂 But yeah I did used a lot of frameworks in Android to allow CMSs to be happy creating deep links between apps and urls in web pages, but never worked well imo. I prefer never to have that kind of dynamic framework. In my case I want pre-defined things, like open Slack app or App Store, and not any url or app. Main issue how to decouple this logic with both Android and iOS, and in future also for desktop and web 😄 I think there is an UiApplication.openUrl thing, given that iOS apps allows custom url queries, as Apple warns for exploits using it. For try catch vs PackageManager I prefer one shot try catch and hope user having the app to be launched. Other variant open up some security things in your own app, expose third party connections kind a. Feeling confident in the Android code itself, but not how to make the code agnostic, as I cant use Uris in iOS 😄 iOS mostly using NSUrl it seems like in their APIs. From what I seen so far NsUrl is very similar to Android Uri in how to parse web url structure of Uri parts etc. But not sure if its the case for all things or not. If thats the case it will work well with web, and for desktop as well I think. The main complexity I think will be things like share Intents, or pick files or media, or request sharing content between iOS and Android 😄 So I will avoid that as much as I can.
👍🏽 1