liveview-native / liveview-client-swiftui

MIT License
349 stars 29 forks source link

Deep Links & Push Notifications #1375

Open petermueller opened 3 weeks ago

petermueller commented 3 weeks ago

I'm investigating building a LVN implementation of our web app, and one of the features we'd probably want early on is Push Notifications that when tapped & handled result in the user having their app launched and the deep link taking them to a specific "web style" route w/ all the query params and niceties.

I'd imagine it would be similar, but it would be nice if it would also work for any registered "app scheme", and regardless if the deep link is coming from a push service that they tapped, or a web page with a custom URI scheme.

In its most basic form, I'm imagining a web page w/ an "Open in the App" button that goes to something like myapp://welcome or myapp://some/path/with/uuid_123?some=param

bcardarella commented 3 weeks ago

@carson-katri there's a good lib in Elixir for reporting to APNS: https://hexdocs.pm/pigeon/2.0.0-rc.2/Pigeon.APNS.html

what we'll need is a way to launch the app with the deep link url from the notification

carson-katri commented 2 weeks ago

The onOpenURL(perform:) modifier will respond to any links that launch your app, and you can update some state to have the LiveView reconnect at the launched URL.

struct ContentView: View {
    @State private var launchURL = URL(string: "https://myapp.example.com")!

    var body: some View {
        #LiveView(launchURL)
            .onOpenURL { url in
                self.launchURL = url
            }
    }
}
carson-katri commented 2 weeks ago

If you're using a URL scheme instead of a universal link, you can extract the path from the url and append it to your base URL.

self.launchURL = URL(string: "https://myapp.example.com")!.appending(path: url.path())