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

查看:104
本文介绍了编写针对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;

(为避免违反保密协议而进行模糊处理)

(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天全站免登陆