# iOS

## iOS integration

Below you can find the code sample for integrating the WebView into and iOS application.

## Integrating the `ContentView` into a Native SwiftUI Application <a href="#integrating-the-contentview-into-a-native-swiftui-application" id="integrating-the-contentview-into-a-native-swiftui-application"></a>

The `ContentView` struct in `ContentView.swift` is a SwiftUI `View` that hosts a `WebView` in a `TabView`. Here's a breakdown of the key components:

### WebView Struct <a href="#webview-struct" id="webview-struct"></a>

The `WebView` struct is a `UIViewRepresentable` that wraps a `WKWebView`. It takes a `URL` and a `Binding` to a `Bool` for reloading the web view.

```swift
struct WebView: UIViewRepresentable {
    let url: URL
    @Binding var reload: Bool
    ...
}
```

### WebsiteView1 Struct <a href="#websiteview1-struct" id="websiteview1-struct"></a>

`WebsiteView1` is a SwiftUI `View` that hosts a `WebView`. It also includes a button for reloading the web view.

```swift
struct WebsiteView1: View {
    @State private var reload: Bool = false
    ...
}
```

### ContentView Struct <a href="#contentview-struct" id="contentview-struct"></a>

The `ContentView` struct is a SwiftUI `View` that hosts a `TabView` with `WebsiteView1`.

```swift
struct ContentView: View {
    var body: some View {
        TabView {
            WebsiteView1()
                .tabItem {
                    Label("FAN View", systemImage: "1.square.fill")
                }
        }
    }
}
```

To integrate this `ContentView` into a native SwiftUI application, developers would need to include this view in their application, ensure the necessary `WebView` and `WebsiteView1` structs are available, and adjust the URL and tab name as needed.

### &#x20;Full code for ContenView\.swift:

```swift
import SwiftUI
import WebKit

struct WebView: UIViewRepresentable {
    let url: URL
    @Binding var reload: Bool

    func makeUIView(context: Context) -> WKWebView {
        let webViewConfiguration = WKWebViewConfiguration()
        webViewConfiguration.allowsInlineMediaPlayback = true
        webViewConfiguration.mediaTypesRequiringUserActionForPlayback = []


        let webView = WKWebView(frame: .zero, configuration: webViewConfiguration)
        webView.load(URLRequest(url: url))
        return webView
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
        if reload {
            uiView.reload()
        }
    }
}

struct WebsiteView1: View {
    @State private var reload: Bool = false
    var body: some View {
        VStack {
            Button(action: {
                reload.toggle()
            }){
                Image(systemName: "arrow.clockwise")
                    .resizable()
                    .frame(width: 20, height: 20)
            }
            .padding()
            WebView(url: URL(string: ""<<url to the relevant template>>")!, reload: $reload)
        }
    }
}

struct ContentView: View {
    var body: some View {
        TabView {
            WebsiteView1()
                .tabItem {
                    Label("FAN View", systemImage: "1.square.fill")
                }
        }
    }
}
```

### Entry point for the ContentView: <a href="#entry-point-for-the-contentview" id="entry-point-for-the-contentview"></a>

To start your SwiftUI application you need some entry point. It hosts the ContentView which in turn hosts a WebView in a TabView. Here's a breakdown of the key components:\
\
The cdn\_uiApp struct is the main entry point of your SwiftUI application. It defines the scene-based life cycle with the @main attribute and contains the body property which returns a Scene.

```kotlin
@main
struct cdn_uiApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
```

In the body property, a WindowGroup is created which will automatically create a new window for each platform your app supports. Inside this WindowGroup, the ContentView is initialized.

### Permissions <a href="#permissions" id="permissions"></a>

To allow a WebView application based on WebRTC to work properly, you have to provide privacy permissions in your `.xcodeproj` file for the camera and microphone

The following permissions are required to enable WebView to work fully. If you prefer to only have a viewing experience, then you might skip these permissions

<figure><img src="/files/8ApKGgAN20Yc9ACwp0cI" alt=""><figcaption></figcaption></figure>

&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.sceenic.co/celebrity-watch-party/ios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
