How to split Code for iOS 3.0 and iOS 3.2 so I can use MPMoviePlayerViewController if OS 3.2++

前端 未结 2 2075
悲哀的现实
悲哀的现实 2020-12-17 06:00

I have a video that I play. To use full screen in iOS 3.2 I use the MPMoviePlayerViewController (seems to only work with that Class). But if I want to build for iOS 3.0 I ob

相关标签:
2条回答
  • 2020-12-17 06:31

    I'm not sure if this is what you are trying to do, but as per Apple's recommendation for universal apps in the iPad Programming Guide, if you want to build for multiple OS versions with inconsistent APIs, you should use NSClassFromString, and go from there. This way, you only have to have one target (the lowest OS you support) and through out your code have things like

    Class mplayerControllerClass = NSClassFromString(@"MPMoviePlayerViewController");
    if(mplayerControllerClass != nil) {
       //Code for 3.2, e.g. [mplayerControllerClass alloc]
    } else {
       //Code for pre-3.2 OSes
    }
    
    0 讨论(0)
  • 2020-12-17 06:38

    Try this...

    #ifdef IPHONE_OS_3.2
    
    /* iOS 3.2 code */
    
    #endif
    
    #ifdef IPHONE_OS_3.0
    
    /* iOS 3.0 code */
    
    #endif
    

    ...the offending code will get removed before the compiler sees it.

    0 讨论(0)
提交回复
热议问题