0
votes

We're building an app that deals with the iPhone address book. In version 4.0 Apple implemented sources in the address book, and also a couple of methods for these (to retrieve sources, write to a source etc.). This functionality was not present in iOS smaller than 4.0.

We have updated our app to fit around 4.0 and 4.2 way of dealing with address book sources, but I haven't tested it on a 3.0 device.

In general, will the app break if you are using more recent SDK methods on an older version of the operating system that doesn't have them?

Thanks!

2

2 Answers

2
votes

Yes, it will crash.

Either do a check on which version of iOS the app is running to determine whether to use a certain functionality or put the calls in question within if ([object respondsToSelector:@selector]) {}.

If you don't want to deal with this and make sure it will never crash, just make your app available for iOS 4.0 and higher.

2
votes

yes, it will crash. But there are ways to prevent this.

Yesterday I did something similar with Event Kit.

I created my own EventHandler object that returns nil in init if there is no Event Kit. Calls to nil are perfectly legal so this abstraction class prevents crashes on iOS3. And I don't need to do the NSClassFromString check for every call I make.

Due to lack of iOS3 devices I couldn't test it yet, but I hope it'll work.

- (id)init {
    self = [super init];
    if (self) {
        Class eventKitClass = NSClassFromString(@"EKEventStore");
        if(eventKitClass) {
            // iOS4++
            // more init
        }
        else {
            // iOS3
            [self release];
            return nil;
        }
    }
    return self;
}

you have to weak link the Event Kit framework. [Targets/YourTarget/Get Info/General]

EDIT: I misread your question, you aren't asking about the event kit. But the approach works for the adressbook framework too.

EDIT2: Since addressbook was available since iOS 2.0 my approach is useless for you.
You have to use

if ([foo respondsToSelector:@selector(doSomething:)]) { 
    [foo doSomething:bar]; 
}

for each call you make that might not be present in iOS3. Like the other answerer said.