Sceenic - WatchTogether
  • Watch Together and Synchronization SDKs
  • Watch together SDK
    • Watch Together SDK overview
    • Authentication overview
    • Tutorials
      • Android
        • Android - Java/Kotlin
      • iOS
        • iOS Swift/Objective-c adapter
      • Web
        • Authentication
        • Create a New Project
        • Adding WT SDK library to the project
        • Installing the NPM package
        • Sample application
          • The conference skeleton
          • Connecting to a Session
          • How to turn on and off video and audio
          • How to change video quality
          • Errors handling
          • Leave the call
        • Support
    • API references
      • Android reference
        • Session
        • SessionListener
        • SessionReconnectListener
        • SessionConnectionListener
        • Participant
          • ParticipantType
        • SessionError
      • iOS Swift reference
        • Session
        • SessionDelegate
        • Participant
        • ParticipantActiveSpeakerDelegate
        • ParticipantDelegate
        • LocalParticipant
        • WTError
        • DataTypes
      • iOS Objective-c adapter reference
        • SessionAdapter
        • SessionAdapterDelegate
        • ParticipantAdapter
        • LocalParticipantAdapter
        • ParticipantAdpaterDelegate
        • ParticipantAdapterActiveSpeakerDelegate
        • NSError
        • DataTypes
      • Web reference
        • WT Session
          • WTSession.connect(sToken, pName, uC, m)
          • WTSession.connectAsAViewer(sToken, pName)
          • WTSession.connectWithSharingScreen(sToken, pName)
          • WTSession.disconnect()
          • WTSession.enableStats()
          • WTSession.sendMessage(msg)
          • WTSession.sendPlayerData(time)
          • async WTSession.getSessionState()
        • SessionListeners
          • WTSessionListeners.onConnected(fn)
          • WTSessionListeners.onDisconnected(fn)
          • WTSessionListeners.onStreamCreated(fn)
          • WTSessionListeners.onLocalStreamCreated(fn)
          • WTSessionListeners.onMosReport(fn)
          • WTSessionListeners.offMosReport(fn)
          • WTSessionListeners.onMessageReceived(fn)
          • WTSessionListeners.onSyncData(fn)
          • WTSessionListeners.onIceDisconnected(fn)
        • Participant
          • setMediaQuality
        • ParticipantListeners
        • ErrorsListeners
        • ReconnectListeners
        • MediaDevices
      • Cluster authentication service reference (CAS)
  • Synchronization SDK
    • Synchronization SDK overview
    • Tutorials
      • Android
        • Android - Java/Kotlin
      • iOS
        • iOS - Swift/Objective-c
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
        • v2.0 Migration Guide
    • API references
      • Android reference
        • SynchSDK
        • SynchListener
      • iOS reference
        • SynchSDK
        • SynchListener
      • Web reference
  • Celebrity SDK
    • Celebrity SDK overview
    • Tutorials
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
    • API References
      • Web reference
  • Chat SDK
    • Chat SDK overview
    • Tutorials
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
    • API Refences
      • Web reference
  • Public Chat SDK
    • Public Chat SDK overview
    • Tutorials
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
    • API Refences
      • Web reference
  • Celebrity Watch Party
    • Web application
    • Android
    • iOS
    • Celebrity View & Fan View
Powered by GitBook
On this page
  • iOS integration
  • Integrating the ContentView into a Native SwiftUI Application
  • WebView Struct
  • WebsiteView1 Struct
  • ContentView Struct
  • Full code for ContenView.swift:
  • Entry point for the ContentView:
  • Permissions

Was this helpful?

  1. Celebrity Watch Party

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

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

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.

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

WebsiteView1 Struct

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

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

ContentView Struct

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

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.

Full code for ContenView.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:

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.

@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

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

PreviousAndroidNextCelebrity View & Fan View

Last updated 6 months ago

Was this helpful?