I have an app where users can open videos from UIWebview, including Youtube ones. In iOS7, I was able to get a notification when it started playing, or when it became full s
update for Swift 4.2, iOS 12.1 and WKWebView:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// listen for videos playing in fullscreen
NotificationCenter.default.addObserver(self, selector: #selector(onDidEnterFullscreen(_:)), name: UIWindow.didBecomeVisibleNotification, object: view.window)
// listen for videos stopping to play in fullscreen
NotificationCenter.default.addObserver(self, selector: #selector(onDidLeaveFullscreen(_:)), name: UIWindow.didBecomeHiddenNotification, object: view.window)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// remove video listeners
NotificationCenter.default.removeObserver(self, name: UIWindow.didBecomeVisibleNotification, object: view.window)
NotificationCenter.default.removeObserver(self, name: UIWindow.didBecomeHiddenNotification, object: view.window)
}
@objc func onDidEnterFullscreen(_ notification: Notification) {
print("video is now playing in fullscreen")
}
@objc func onDidLeaveFullscreen(_ notification: Notification) {
print("video has stopped playing in fullscreen")
}