如何在 iOS 8 的全屏模式下在 UIWebView Player 中接收通知?

How to receive Notification in UIWebView Player for full screen mode in iOS 8?

我想在 UIWebView 中以全屏模式播放视频后做一些事情。 所以,我想要来自 UIWebView 的消息,用于进入全屏和退出全屏。

在 iOS 7 我通过以下内容收到通知:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(VideoEnterFullScreenHere:)
                                             name:@"UIMoviePlayerControllerDidEnterFullscreenNotification"
                                           object:self.view.window];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(VideoExitFullScreenHere:)
                                             name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                           object:self.view.window];

但是在iOS8中,它不能正常工作。

以下内容适合我。 希望对其他人有所帮助!

在你的AppDelegate.mclass,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowBecameHidden:) name:UIWindowDidBecomeVisibleNotification object:nil];

    return YES;
}

并以此接收,

- (void)windowBecameHidden:(NSNotification *)notification {

    UIWindow *window = notification.object;

    if (window != self.window) {
        NSLog(@"Online video on full screen.");
    }
}

谢谢!

使用 AVPlayer 通知代替 UIMoviePlayer 通知。

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playerItemInitiated:)
                                                 name:@"AVPlayerItemBecameCurrentNotification"
                                               object:nil];