4

Ok I've been developing iphone-apps for over a year now, but there's this one thing which still really sucks.

Let's say I want to make my app compatible with iOS 3.0 I set my sdk to the newest version available and set my deployment target to 3.0

But what happens, if you by accident call a function available only in ... 3.1.x or later? Right, it simply crashes.

There are no warnings or indicators telling you, that a function is only available in later iOS-Version. And since the Emulator doesn't support versions < 4.0 it's impossible to test if the application really works. You can't even buy a new device since they already have a newer iOS installed. And even if you have an older device it's sometimes almost impossible to check each and every part of your code.

And I really need to support older versions since I know that my customers (around 2/3) still use 3.x versions.

Isn't there ANY code-analyzer or something that scans the availability of all functions called within the app?

In one case the app crashed because I called

+ (id)sortDescriptorWithKey:(NSString *)key ascending:(BOOL)ascending

which i a convenience method of alloc +

- (id)initWithKey:(NSString *)key ascending:(BOOL)ascending;

(Plus it's autoreleased) But sortDescriptorWithKey is only avaible in 4.0 @_@

4

3 回答 3

2

同样的问题在这里。我唯一想到将Base SDKProject AND Target 设置为 3.0。然后编译器会检查你是否调用了一些不存在的方法。

但是扫描仪的问题仍然存在,因为上面的方法在使用 ASI HTTP 框架时会引发一些错误。所以我的程序是

  1. 将 SDK 更改为 3.0
  2. 经历构成我自己的代码基础的错误
  3. 将方法更改为与 3.0 兼容
  4. 将项目设置Base SDK回最新的 SDK

您可能必须从以前的 XCode 版本安装 SDK 3.0。并且无需将目标设置Base SDK回最新版本。我曾经将它设置为 3.0 并且没有从 ASI HTTP 得到错误。

//编辑:XCode 3.2.1 的下载链接:Snow LeopardLeopard

于 2011-01-14T12:59:06.757 回答
0

尝试通过调用 respondsToSelector 方法进行检查

if([your_obj respondsToSelector:@selector(sortDescriptorWithKey:ascending:)]){
  // call sortDescriptorWithKey
}
else
{
  // call another method
}

您将在编译时收到警告,但在运行时不会崩溃。

于 2011-01-14T13:38:24.997 回答
0

尝试使用Apple 的框架/弱链接指南中建立的指南。对于您无法像@Andriy 的回答中那样询问对象的功能。

于 2011-01-14T15:25:37.913 回答