Search code examples
iosiphonempmovieplayercontrollerairplay

enable MPMoviePlayerViewController airplay


I am trying to enable airplay in my application using setAllowAirplay but its showing below warning.

MPMoviePlayerViewController may not respond to 'setAllowsAirPlay'

So please suggest how can I enable airplay in my application.


Solution

  • The warning is there because not all iOS versions and devices include the allowsAirPlay property. The safe way to call it would be like this:

    if ([moviePlayerVC.moviePlayer respondsToSelector:@selector(setAllowsAirPlay:)]) {
        [moviePlayerVC.moviePlayer setAllowsAirPlay:YES];
    }
    

    I'm pretty sure that this selector will exist on any modern iOS device.