This repository contains an Xcode project written in Swift, which uses SwiftUI and WebKit to create a WKWebView-based app. The purpose of the app is to load an external webpage, receive messages from this webpage, and update the SwiftUI view based on these messages.
The code uses SwiftUI for UI development, and it includes a custom WKWebView view which is able to receive messages from the JavaScript of the loaded webpage. Additionally, it uses the NavigationStack concept for managing navigation based on the received messages.
- macOS with Xcode installed
- Swift 5.3 or later
- iOS 13.0 or later
- Clone the repository:
git clone https://github.com/Legit-Health/iframe-demo-ios/tree/master- Navigate to the project directory:
cd IframeTest- Duplicate the
AppConfig.samplefile and rename the new file toAppConfig.swift:
cp AppConfig.sample AppConfig.swift- Open the
AppConfig.swiftfile and fill in yourcompanyIdentifier:
import Foundation
struct AppConfig {
static let companyIdentifier = "YourCompanyIdentifier"
}-
Open the project in Xcode by double clicking on
IframeTest.xcodeproj. -
Build and run the project.
The app will load a webpage from a defined URL with the companyIdentifier as part of the query parameters. The webpage can send messages to the app through JavaScript, which will then be received and processed by the app, leading to navigation within the app.
-
WebViewstruct: This is a SwiftUI view which represents the WKWebView. It's set up to receive messages from the webpage through theWKScriptMessageHandlerprotocol. It also manages the navigation of the WebView. -
Coordinatorclass: This is a delegate for WKWebView which handles the WebView's lifecycle and received messages. -
ContentViewstruct: This is the main view of the app, which includes the WebView and manages the navigation stack. -
ImageSentstruct: This is a SwiftUI view which is shown when a particular type of message is received by the WebView.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please see the LICENSE file for details.
Gerardo Fernández Moreno - gerardo@legit.health
Project Link: https://github.com/Legit-Health/iframe-demo-ios