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 @_@

Infinite
  • 2,931
  • 2
  • 27
  • 33

3 Answers3

2

same question here. The only thing I figured out to set the Base SDK of Project AND Target to 3.0. Then the compiler will check if you call some not existing methods.

But the question for a scanner still exist because the method above throws me some errors when using the ASI HTTP framework. So my procedure is to

  1. change the SDK's to 3.0
  2. go through errors which underlie my own code
  3. change the methods to be 3.0 compatible
  4. set the project's Base SDK back to latest SDK

you probably have to install a SDK 3.0 from previous XCode version. And there is no need to set the target Base SDK back to latest version. I have once set it to 3.0 and get no errors from ASI HTTP.

//EDIT: download links for XCode 3.2.1: Snow Leopard and Leopard

  • download links added, you have to sign in with your developer account before downloading ;) –  Jan 14 '11 at 14:53
  • Thx :) Now I've got to copies of xcode installed at the same time, but at least i can code against older SKDs – Infinite Jan 16 '11 at 03:03
  • you can also install only the SDKs without a copy of XCode: open terminal and navigate to the DVD, then go into subdirectory /packages and there are all the SDKs which you can install separately. Make sure to install both, device and simulator! After the installation you have to move the new folder created in root (/) to your XCode directory ;) –  Jan 16 '11 at 11:44
0

Try to check by calling respondsToSelector method

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

You will receive warnings while compiling but not crashes in run time.

Andriy
  • 1,864
  • 1
  • 12
  • 10
  • That's not a real solution to the problem, though. You can't run every single method through a branch like that and there's no good way to check to see if a particular method call existed in previous OS versions. Apple really needs to start including old SDKs in their releases so you can easily set the base SDK to something old, then test on the simulator. – kubi Jan 14 '11 at 13:44
  • Sure you can't check every method in such way, but it may be helpful if it is needed to check few methods. – Andriy Jan 14 '11 at 14:02
0

Try using the guidelines established in the Apple's Framework/Weak-linking guide. for functions that you can't ask the objects like in @Andriy's answer.

Stephen Furlani
  • 6,794
  • 4
  • 31
  • 60
  • the problem isn't handling functions which are known to be not available. The problem is recognizing which functions aren't available ;) – Infinite Jan 20 '11 at 20:44
  • @Infinite, [try this answer here](http://stackoverflow.com/questions/3056016/alternatives-to-weak-linking-in-iphone-sdk/3056136#3056136) and as far as knowing which before you code, check the headers (Jump to Definition). They'll tell you. – Stephen Furlani Jan 20 '11 at 20:53