编写针对 iOS 6 Base SDK 编译的 iOS7 代码 [英] Writing iOS7 code that compiles against iOS 6 Base SDK

查看:15
本文介绍了编写针对 iOS 6 Base SDK 编译的 iOS7 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们现在有一个 iOS 应用程序在售,我们正在使用相同的代码库在 XCode 5 DP 上开发 iOS 7 版本.

We have an iOS app on-sale now, and we're developing the iOS 7 version on XCode 5 DP using the same code base.

我们现在确实需要为现有的 iOS 5/6 客户发布更新,但是,当然,当我们将项目重新加载到 XCode 4 中时,它会抱怨不存在的属性,因为 Base SDK 然后变成了 iOS6,不是 7:

We really need to release an update right now for existing iOS 5/6 customers but, of course, when we re-load the project into XCode 4, it complains about non-existing properties since the Base SDK then becomes iOS6, not 7:

// Only run this bit on iOS 7
if ([self respondsToSelector:@selector(setFooForExtendedLayout:)])
{
    self.fooForExtendedLayout = UIFooEdgeLeft | UIFooEdgeRight;
}

float bottomOffset = 0;
// Only run this bit on iOS 7, else leave bottomOffset as 0
if ([self.hostController respondsToSelector:@selector(bottomLayoutFoo)])
    bottomOffset = self.hostController.bottomLayoutFoo.length;

(为避免破坏 NDA 进行了混淆处理)

(obfuscated to avoid breaking NDA)

XCode 错误:

在类型的对象上找不到属性fooForExtendedLayout"'UIViewController *'

Property 'fooForExtendedLayout' not found on object of type 'UIViewController *'

使用未声明的标识符UIFooEdgeLeft"

Use of undeclared identifier 'UIFooEdgeLeft'

使用未声明的标识符UIFooEdgeRight"

Use of undeclared identifier 'UIFooEdgeRight'

在UIViewController *"类型的对象上找不到属性bottomLayoutFoo"

Property 'bottomLayoutFoo' not found on object of type 'UIViewController *'

注释掉这个新代码会很痛苦.重写它以与新旧 Base SDK 兼容的正确方法是什么?现在提交它(通过 XCode 4 并针对 iOS 6 SDK 构建)是否有任何形式的 App Store 拒绝风险?

It would be a pain to comment out this new code. What is the correct way to re-write it to be compatible with both the old and new Base SDKs, and does submitting it now (via XCode 4 and built against iOS 6 SDK) risk any sort of App Store rejection?

推荐答案

我建议等到 iOS 7 准备好提交更新.
但是,它们是解决问题的方法.

I would advise to wait until iOS 7 is ready to submit your update.
However, they are ways to fix the issue.

在类型的对象上找不到属性fooForExtendedLayout"'UIViewController *'

Property 'fooForExtendedLayout' not found on object of type 'UIViewController *'

由于属性只是一个语法糖,修复这种错误的简单方法是使用选择器调用方法(setter):

As properties are just a syntactic sugar, the easy way to fix this kind of error is to use a selector to call the method (setter):

[ self performSelector: NSSelectorFromString( "setFooForExtendedLayout:" ) withObject: ( id )xxx ];

@selector() 无法使用,因为您要求的是带有 iOS 6 SDK 的 iOS 7 选择器.
因此使用 NSSelectorFromString.
顾名思义,withObject 参数是为对象制作的.但是由于对象是指针,并且您的方法采用枚举值,因此您实际上可以使用强制转换毫无问题地传递它.

@selector() can't be used since you're asking for an iOS 7 selector with an iOS 6 SDK.
Hence the use of NSSelectorFromString.
The withObject argument is made for objects, as it names implies. But as objects are pointers, and as your method takes an enum value, you can actually pass it without problem, using a cast.

使用未声明的标识符UIFooEdgeLeft"
使用未声明的标识符UIFooEdgeRight"

Use of undeclared identifier 'UIFooEdgeLeft'
Use of undeclared identifier 'UIFooEdgeRight'

现在关于您的枚举值,没有这样的技巧.
唯一的方法是声明它们,使用与 iOS 7 SDK 中相同的值,并祈祷它在正式发布之前不会改变.

Now about your enum values, there's no such trick.
The only way is to declare them, with the same values as in the iOS 7 SDK, and pray that it won't change until the official release.

所以现在由你决定......就我个人而言,我会等待.

So now it's up to you... Personally, I would wait.

这篇关于编写针对 iOS 6 Base SDK 编译的 iOS7 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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