Search…
In iOS apps
Below are the recommended approaches to embed a Whereby room depending on the iOS version.

iOS 14.5 and onwards

WKWebView supports embedding pages that use WebRTC from iOS 14.5 onwards. To access the microphone and camera, it is necessary to add both NSMicrophoneUsageDescription and NSCameraUsageDescription keys to the app’s Info.plist file.
Swift
1
import WebKit
2
3
class WKWebViewController: UIViewController, WKNavigationDelegate {
4
5
public var roomUrlString = "" // Replace by your own
6
private var webView: WKWebView!
7
8
override func viewDidLoad() {
9
super.viewDidLoad()
10
let config = WKWebViewConfiguration()
11
config.allowsInlineMediaPlayback = true
12
webView = WKWebView(frame: view.frame, configuration: config)
13
webView.navigationDelegate = self
14
view = webView
15
guard let roomUrl = URL(string: roomUrlString) else {
16
return
17
}
18
webView.load(URLRequest(url: roomUrl))
19
}
20
}
Copied!

iOS 14.3 and 14.4

For iOS 14.3 and 14.4 use SFSafariViewController to open a website containing an iframe with its src specified as a Whereby room, alongside a custom user interface:
Swift
1
import SafariServices
2
3
class ViewController: UIViewController, SFSafariViewControllerDelegate {
4
5
public var roomUrlString = "" // Replace by your own
6
7
override func viewDidAppear(_ animated: Bool) {
8
super.viewDidAppear(animated)
9
guard let roomUrl = URL(string: roomUrlString) else {
10
return
11
}
12
let safariVC = SFSafariViewController(url: roomUrl)
13
safariVC.delegate = self
14
present(safariVC, animated: true)
15
}
16
}
Copied!

iOS 14.2 and earlier

Redirect to a browser (Safari by default) for iOS versions lower than 14.3:
Swift
1
import UIKit
2
3
class ViewController: UIViewController {
4
5
public var roomUrlString = "" // Replace by your own
6
7
override func viewDidLoad() {
8
super.viewDidLoad()
9
guard let roomUrl = URL(string: roomUrlString),
10
UIApplication.shared.canOpenURL(roomUrl) else {
11
return
12
}
13
UIApplication.shared.open(roomUrl)
14
}
15
}sw
Copied!

Handling multiple iOS versions

Here is an example on how to handle different solutions, depending on the iOS version:
Swift
1
if #available(iOS 14.5, *) {
2
// Use WKWebView
3
} else if #available(iOS 14.3, *) {
4
// Use SFSafariViewController
5
} else {
6
// Redirect to browser app
7
}
Copied!
When the app is sent to background, the camera is disabled. If you need the microphone to continue working while the app is in the background, we recommend redirecting to Safari app.
To use Whereby with Cordova (Phonegap) please use the plugin for SafariViewController