开发者

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 i开发者_StackOverflown 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.


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.


I have done it as follows:

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_4_2
        mMoviePlayerController.allowsAirPlay = YES;        
#endif

It works fine. One of these two answers can be adapted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜