views:

46

answers:

2

Hey,
I'm developing an iPhone application and my target is 3GS and 4G devices.
iOS 4 introduces methods thats deal with multitasking and newer methods to deal with foreground/background lifecycle events.
These new methods aren't available in iOS 3 which simply quits the app and doesn't run it in the background.
Any tips on how to create apps that run on iOS 3 and iOS 4?

A: 

The iPad Programming Guide (I know, not what you'd expect) has a section on universal apps that shows you how to check that symbols exist at runtime. It applies to your question as well.

Start here: https://developer.apple.com/library/ios/documentation/General/Conceptual/iPadProgrammingGuide/StartingYourProject/StartingYourProject.html#//apple_ref/doc/uid/TP40009370-CH9-SW3

Robot K
A: 

I put all my ios4 functions in one section, then wrap a compiler macro(so xcode lets you compile) around them and have functional checking inside each function(so once compiled, your code runs without crashing).. for example

    //Define Logic for conditional code based on version of iOS
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
- (void)applicationDidEnterBackground:(UIApplication *)application {
    //SPECIAL CASE:For OS versions before 4.0, background processes are not supported
    if (backgroundSupported) {
         <IOS4 CODE GOES HERE>
    }
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    if (backgroundSupported) {
        if (backgroundSupported) {
         <IOS4 CODE GOES HERE>
    }
}

- (BOOL)checkBackgroundSupported {
    UIDevice* device = [UIDevice currentDevice];
    backgroundSupported = NO;
    if ([device respondsToSelector:@selector(isMultitaskingSupported)])
        backgroundSupported = device.multitaskingSupported;
    return backgroundSupported;
}
#endif