Multitasking for ios4 but remaining compatible with 3.x

Discussion in 'iPhone/iPad Programming' started by mraheel, Jul 8, 2010.

  1. macrumors regular

    Joined:
    Apr 18, 2009
    #1
    Perhaps this is the most widely asked/answered question everywhere.. i couldnt figure out this one thing..

    To enable multitasking, We HAVE TO SET THE BASE SDK 4.0 in project settings. that does the job alright...

    but after that, does it remain compatible with 3.x?.. its only those 4 methods in appdelegate that were added... will they be ignored in 3.x? and whats the way to test it???
     
  2. macrumors member

    Joined:
    Jun 25, 2010
    #2
    This been answered a few times in here... Set the base SDK to 4.0, then further down there is setting for target OS, set that to 3.0.
     
  3. macrumors newbie

    DemonJim

    Joined:
    Jun 19, 2010
    Location:
    UK
    #3
    Yes correct, when running on 3.x hardware it won't use the new 4.0 delegate functions. You must still provide the applicationWillTerminate etc. functions for these cases.

    Best way to test is as always try it on actual hardware (eg keep an old iPod touch or an iPad on 3.x for this reason).
     
  4. thread starter macrumors regular

    Joined:
    Apr 18, 2009
    #4
    Thanks for the help guys..

    Yea, I changed the Deployment Target to 3.0 and tested it fine in the simulator.. I recently upgraded my itouch to ios4, before the app was working just fine on ios 3.0.

    I just have to add some code to DidEnterBackground delegate function. (applicationWillTerminate will do the job in 3.x).

    However, in Distribution (FINAL Compile before app submission), I should choose BASE SDK 4.0, obviously, but what should the the Deployment target?
     
  5. macrumors member

    Joined:
    Jun 25, 2010
    #5
    I would leave the base SDK as 4.0 and the target OS as 3.0. This will give 4.0 users the new features, but make your minimum OS requirement 3.0 so users with older software can still download it.
     
  6. macrumors newbie

    DemonJim

    Joined:
    Jun 19, 2010
    Location:
    UK
    #6
    If you're supporting 3.x then ensure you test it on actual 3.x hardware - the simulator is not an emulator. You risk customers getting crashes (eg by calling a 4.0 API) which will only result in 1 star ratings, ie not good!
     
  7. thread starter macrumors regular

    Joined:
    Apr 18, 2009
    #7
    Yes, ur right.. will test it on 3.x hardware.

    Im gonna hijack this topic to something a little relevant..
    I've been trying to save state of the application by writing to NSUserDefaults.

    Looking at the WWDC videos, They suggested that we do all our save settings routine in appDidEnterBackground method.. cause potentially it could be the last method before exit. and ApplicationWillTerminate isnt called at all if the user just deletes the app from multitasking menu.

    It doesnt seem to work for me..

    appDidEnterBackground has the following code:

    Code:
    	if(bookmarkArray.count > 0)
    	[[NSUserDefaults standardUserDefaults] setObject:bookmarkArray forKey:@"bookmarks"];
    	else
    	[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"bookmarks"];
    	[self.mainController saveOnTerminate]; //this also writes to NSUserDefaults 
    Everything seems to work well in 3.x

    Has there been anything different with regard to NSUserDefaults in 4.0?
     
  8. thread starter macrumors regular

    Joined:
    Apr 18, 2009
    #8
    okay, got the answer to that, apparently u have to synchronize the userdefaults.. cuz that isnt happening in appDidEnterBackground

    [defaults synchronize]; did the trick
     

Share This Page