Search code examples
iosobjective-cvideouiwebviewvideo-player

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


I want to do some stuff after video playing in full screen mode in UIWebView. So, I want message from UIWebView for entering in full screen & exit from full screen.

In iOS 7 I am getting notification by below stuff:

[[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];

But in iOS 8, it is not working properly.


Solution

  • Below stuff is worked for me. I hope it will help others!

    In your AppDelegate.m class,

    - (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;
    }
    

    And receive it by this,

    - (void)windowBecameHidden:(NSNotification *)notification {
    
        UIWindow *window = notification.object;
    
        if (window != self.window) {
            NSLog(@"Online video on full screen.");
        }
    }
    

    Thank You!