iphone - MPMoviePlayerController - How to write code that works on older versions of iOS also
I'm using MPMoviePlayerCo开发者_如何学Gontroller in my application. When I ran the application on iOS 4.2 device, its working fine. But when running on iOS 3.1.3 device its crashing saying that duration, controlStyle etc are not available in older iOS SDK. I set the target deployment device to 3.1. Its building well. What should I do to make my app play video on latest as well as old iOS.
You can check current iOS version via [[UIDevice currentDevice] systemVersion], and on older versions don't use that properties which causes an error.
If you look in the documentation you will see:
controlStyle
The style of the playback controls.
@property(nonatomic) MPMovieControlStyle controlStyle
…
Availability
Available in iOS 3.2 and later.
I had the same problem and figured out that it doesn't check on 3.0 functions if you set the deployment target to 3.0.
What I have done to check it I set the project Base SDK to 3.0 (which can stay all the time on 3.0) and set the Base SDK of my target to 3.0 (this must set back to 4.0 because otherwise I get some strange warnings). If you set your target Base SDK to 3.0 then XCode will check if all your functions exist in iOS SDK 3.0.
If you don't have the option to choose SDK 3.0 in Base SDK you have to download an old XCode version and install the SDK manually. (open DVD goto /packages and install SDK 3.0 for Simulator and Device)
You can check info here. http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html#comment-36453
But, if you use nested controller, then some function such as paging will not work because of the modal view controller. The delegate should be assigned properly, but I don't know how to assign that. If anyone knows, please provide some instructions.
精彩评论