Prototype demonstrating two-way communication between a webview (Reactjs app) and SwiftUI. i.e., execute native code from the webview JavaScript and execute webview JavaScript code from native.
You've are building a product that requires some sort of hardware functionality, like bluetooth, camera, or NFC but you are on a tight budget and can't afford to build and maintain a 100% native app. So, you build the common UI with Reactjs and use native code to handle the hardware functionality.
- Xcode 15
- Nodejs LTS
- Clone the repo
cd
to my-react-app, runnpm install
- run
npm run build
- run
npm run preview -- --host
- open ReactCommunication.xcodeproj in Xcode
- Change the signing team to your team
- Change the value of
reactAppURLString
inContentView.swift
to the URL from step 4 - Run the app
- tap some buttons to see the communication in action