ios4compilationios-4.2airplay

allowsAirPlay support and iOS 4.2, iOS4.3


I am developing an iPhone application in which I want to support Air Play. My app should be able to run on iPhone device with iOS 4.1 onwards. So, I have selected iOS 4.3 as Base SDK and 4.1 as Deployment Target in Target settings of my App. Now, I want add the code of setting the flag allowsAirPlay on MPMoviePlayerController. This is supported only in iOS 4.3 SDK. What should be the XCode app-target settings and how should the code be written so that

  1. it also compiles in the system in which iOS 4.3 SDK is not installed.
  2. it runs properly in all the iPhone devices with iOS > 4.1
  3. In a iPhone device with iOS 4.3, Air Play feature is enabled.

Solution

  • You'll need to silence compiler warnings by declaring the method in a category, at the top of your implementation file:

    @interface MPMoviePlayerController(MEKAirPlay)
    - (void)setAllowsAirPlay:(BOOL)supports;
    @end
    

    Then, check that the method is actually implemented, before calling it:

    if ([player respondsToSelector:@selector(setAllowsAirPlay:)]) {
      [player setAllowsAirPlay:YES];
    }
    

    You could also wrap the category definition in a preprocessor #if to stop it being seen when compiled with the iOS 4.3 SDK, although I haven't done that. I don't have the earlier SDKs installed, any more, so I can't really test that.