如何拆分iOS 3.0和iOS 3.2的代码所以如果OS 3.2 ++我可以使用MPMoviePlayerViewController [英] How to split Code for iOS 3.0 and iOS 3.2 so I can use MPMoviePlayerViewController if OS 3.2++

查看:81
本文介绍了如何拆分iOS 3.0和iOS 3.2的代码所以如果OS 3.2 ++我可以使用MPMoviePlayerViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我播放的视频。
要在iOS 3.2中使用全屏我使用MPMoviePlayerViewController(似乎只适用于该类)。但是,如果我想为iOS 3.0构建,我显然会遇到几个错误,因为这个类在iOS 3.0中是未知的。我也知道如何在iOS 3.0中使用MPMoviePlayerController得到我想要的东西,但我只能有一个,iOS 3.0的代码或iOS 3.2的代码。

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 obviously get several errors, because this class is not known in iOS 3.0. I also know how to get what I want with MPMoviePlayerController in iOS 3.0, but I can only have one, either the code for iOS 3.0 or the code for iOS 3.2.

如何应对? - 找到解决方案(参见捆绑编辑的底部)

How to cope with that ? - Solution found (see bottom of bundled edit)

我想我必须使用多个目标,你有关于如何做到这一点的建议吗? (总是当我尝试多个目标时,我遇到错误并放弃:))?

I guess I have to use multiple targets, do you have suggestions on how to do that (always when I tried multiple targets I got errors and gave up :) ) ?

编辑捆绑

Edit bundled (multiple edits combined)

首先我认为这样可行。

#ifdef __IPHONE_3_0
// OS 3.0 specific
#endif

但事实并非如此,因为在iOS的Availability.h文件中,您所有的操作系​​统都是从2.0到现在的。因此,如果您为iOS 3.2编译,#ifdef __IPHONE_3_0也会返回true。

But it doesn't because in the iOS's Availability.h files you have all OS's defined from 2.0 up to your current one. So if you compile for iOS 3.2 the #ifdef __IPHONE_3_0 will return true as well.

然后我认为这样可行

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_2
  // Code for older iOS
#else
  // Code for iOS 3.2 up
#end

但它也没有。因为在iOS 3中例如__IPHONE_3_2未定义。

But it doesn't also. Because in iOS 3 for example __IPHONE_3_2 is undefined.

所以我认为我必须创建一些更智能的if / elseif / else块然后我(最后:D)阅读苹果AvailabilityInternal.h文件定义中__IPHONE_X_X上方的注释:

So I thought I would have to create some more intelligent if/elseif/else block but then I (finally :D) read the comment above the __IPHONE_X_X in apples AvailabilityInternal.h file definitions:

它表示你可以使用__IPHONE_OS_VERSION_MIN_REQUIRED来解决这类问题,但你不应该使用__IPHONE_X_X常量因为刚刚发生在我身上的事情......它们根本就没有被定义,因此评估为0.所以他们建议使用这些值。所以我现在有一个像这样的工作选择器...

It says that you can use __IPHONE_OS_VERSION_MIN_REQUIRED for exactly that kind of problem, but that you shouldn't use the __IPHONE_X_X constants because of what just happened to me... they simply might not be defined thus evaluating to 0. So they recommend to use the values instead. So I have a working selector now like this...

(现在这真的工作100%)

(Now this really works 100 %)

#if __IPHONE_OS_VERSION_MIN_REQUIRED < 30200
  // code for iOS below 3.2
#else
  // code for iOS 3.2 ++
#endif


推荐答案

我不确定这是不是你要做的,但是根据Apple对于通用应用程序的推荐iPad编程指南,如果你想构建具有不一致API的多个操作系统版本,你应该使用NSClassFromString,并从那里开始。这样,您只需拥有一个目标(您支持的最低操作系统),并且您的代码中包含类似

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
}

这篇关于如何拆分iOS 3.0和iOS 3.2的代码所以如果OS 3.2 ++我可以使用MPMoviePlayerViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆