How to interop with native code?

What’s the story around interacting with native code?

  • My iOS app is using ApolloClient + interceptors to login and authenticate requests. How can I get that auth info into LiveView Native?
  • I use CLLocationManager to request location permission from the user. How can LiveView Native call out to a native function and handle a response? In ReactNative / Elm / Rescript the answer is to write some sort of bridge/port/binding that handles the interop.

Thanks!

For LiveView Native you will set auth through session store the same way you do in JS which means you are setting a cookie with your session information. Just like in a web LiveView app you submit the form and issue a redirect from the server. This will trigger an app reconnect which will make use of the cookie store along with the session information.

1 Like

Ok, then for dropping LiveView Native into an existing app, I’d need to inject the token into the LiveView Native baseUrl, then handle that token on the Phoenix side? (Eg ElixirConfChat)

And for messages from Phoenix → Native, I’m guessing it’s the LiveView().onReceive(...? Do responses to onReceive get sent over to Phoenix?

Thanks!

It’s the same method as is used with Phoenix Auth

I have a similar use case for authentication happening outside of LiveView Native. I contributed a small change that lets you specify additional headers when instantiating the LiveView.

I use that to pass a long-lived authentication token that’s stored client-side. Phoenix verifies that and then, critically, creates a session token and puts that into the session (using put_token_in_session) which is then automatically handled by LiveView Native in subsequent requests through the web socket.