My application is structured similarly to the expe...
# compose-ios
m
My application is structured similarly to the experimental falling-balls-mpp example from JetBrains. Just recently this example has been modified to use the new
defaultUIKitMain
. I tried to apply that to my application too but I failed to get at the
UIApplication
object in this new setup. As far as I understand the API this object is needed, e.g, to call methods like
openURL
which I need for my application. Does anybody know how to get at the
UIApplication
object or knows an alternative?
l
defaultUIKitMain
seems to be a convenience method for simple use cases. If you need extra functionality, it may be best to do it the old way.
m
Yes, but wouldn’t it be better if the method
defaultUIKitMain
would just return this important object instead of
Unit
? Otherwise this convenience method is not very convenient 😉.
I think I have just discovered the solution to this problem myself. Inside the Compose block you can just call
UIApplication.sharedApplication
which seems to provide what I need. At least my code is working again now and I can open an URL from my iOS Compose (Canvas) application again.
d
Good to know you have a solution @Michael Paus; though you might find you eventually want to go back to packing a framework for Xcode (The 'normal' way). I went on a similar journey recently; initially under the misapprehension that I had to use the Experiment UIKit approach to use Compose/iOS (due to the falling balls example). As I learned (thanks to @Landry Norris) and now proved in my project, you don't - you can keep doing things the better supported 'Framework' way, use Compose, and potentially avoid getting stuck in other ways... like when requiring full control over the Xcode project for packaging. One 'feature' is that you must have a minimal amount of Swift to bootstrap into the Framework; though mine is just:
Copy code
import shared

@main
struct Main {
  static func main() {
      MainKt.main()
  }
}
...and I've seen that others can get that down to a one-liner, even!
m
Interesting. Is there any public example with Compose GUI on iOS for this approach? The advantage of the falling balls approach is that you can completely avoid Swift and Xcode but if you later need more control this may indeed be a dead end road.
l
I use this approach with cocoapods in https://github.com/LandryNorris/MultiFactor
It's on the platform/add-ios-xcode branch in the iosAppXcode folder
a
@Landry Norris Thanks for that 👆
I added a single Text composable but it's over the safe area
@Landry Norris been thinking maybe it's the configuration on the EntryPoint.kt that I need to adjust
l
The safe area isn't respected by compose yet
a
Okay