Before iOS 8, the UIMoviePlayerControllerDidEnterFullscreenNotification
notification was sent any time a media player went to fullscreen from a UIWebView. In iOS 8, this doesn't happen and some have suggested to listen for the AVPlayerItemBecameCurrentNotification
notification instead. This doesn't appear to be sent from WKWebView. Listening for the UIWindowDidBecomeVisibleNotification
notification doesn't work because it's fired for all windows that are added (including things like ad networks)
Bottom line, I've been working on this all night and I can't seem to figure out how to determine if a video was opened in full screen with a WKWebView. Any help would be appreciated.
Edit: To confirm, I created a blank project. Added a UIWebView and the AVPlayerItemBecameCurrentNotification
listener to it and it got triggered when I played a video and it entered full screen. I switched that UIWebView to a WKWebView and that notification was no longer triggered.
This workaround seems to work on iOS8 & iPhone 6
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowBecameHidden:) name:UIWindowDidBecomeHiddenNotification object:nil];
return TRUE;
}
- (void)windowBecameHidden:(NSNotification *)notification {
UIWindow *window = notification.object;
if (window != self.window) { // Not my own window: assuming the video window was hidden, maybe add some more checks here.
// Add code here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With