Apples iOS4 update What’s in it for the developers

Last week at Apples World Wide Developer Conference Steve Jobs unveiled iPhone OS’s yearly major upgrade, introducing a plethora of new functionality. In this post we will try to touch the tip of iceberg in terms of what iOS4 has to offer to the developers.

The first thing you’ll notice about iPhoneOS is that it has been renamed to iOS basically because now it runs on iPads, iPhones & iPod touches & iOS is somewhat a generic name.

Below is the description of new features in the iOS from the developer’s point of view.

Multitasking

The first and foremost thing that catches the attention of developers is the ability of iOS4 to multitask. Multitasking is not a new feature in mobile computing, Palm’s WebOS, Google’s Android & even Microsoft’s Windows Mobile have multi-tasking capabilities. Multitasking application lifecycle is a little different than the traditional application lifecycle that we were used to in Cocoa touch. Apples multitasking implementation is somewhat similar to that of Google’s on the Android platform. Which is in-fact not true multitasking just a mere illusion of multitasking.

When the user wants to switch to another application the state of application is saved or frozen in the memory and when the user gets back to the application the state of application is restored giving an illusion that application was running all along.

When the application is inactive it is barred from any processing except if the application has registered as one of the following

  • Location (GPS related)
  • Audio
  • VoIP (Voice over IP)

This is how application state is specified in the UIApplication.h header file

typedef enum {

UIApplicationStateActive,

UIApplicationStateInactive,

UIApplicationStateInBackground

} UIApplicationState;

Illustrating that we have three application states on the iOS4.

  • Active
  • Inactive
  • In Background

When the application is launched we will receive the usual message from the app delegate

- (void)applicationDidFinishLaunching:(UIApplication *)application

didfinishLaunchingWithOptions(NSDictionary *)launchOptions

In addition to this we will now also receive this message

-   (void)applicationDidBecomeActive:(UIApplication *)application

When going to the background we will receive these messages

- (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application

When in background there are no guarantees that the app will remain in the memory for the entire eternity. If there is a OOM(Out Of Memory) call the runtime will kill our application & free some memory.

When our application comes back to foreground these two methods will be called by the app delegate.

- (void)applicationWillEnterForeground:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application

We can implement our logic in these two delegates; like connecting to the server again or whatever the logic of our application demands.

iOS4 also gives us the functionality to ask for a little more time for processing when the application is being suspended so that we can save state or finish the job for that matter before getting suspended. These are the two calls we can use to tailor our app to our requirements.

-   (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler: (void(^)(void))handler;

-   (void)endBackgroundTask:(UIBackgroundTaskIdentifier)identifier;

*Notice the weird looking syntax (void(^)(void)), this is known as a block & is a recent addition to the C, C++, Objective C & objective C++ by Apple & is abundantly used in many Foundation classes so understanding it is very crucial, more on it later.

Local Notifications

A new feature in iOS4 is of local notification system, this feature somewhat mimics the Apples Push Notification System but is local to the device. Any application can register for notifications locally on the device & the device can then send periodic updates as specified or can change the application badge or do all of the stuff that was possible with Push Notification System. For more information on Local Notification be sure to check out the UILocalNotification.h header file.

UIAutomation

UIAutomation is a new framework that Apple has introduced with the iOS4 SDK. Now you can write Javascript based scripts to automate user testing & check your application rigorously. You can run your scripts along with all the performance tracking systems included in the SDK like Instruments or Shark.

Event Kit

Enables the developers to access the calendar of the user on the device, so that the developer can create, edit, remove & search events on the calendar locally & or any online calendars users are using. Developers will also be able to record change notifications for the events on the calendar.

iAd

iAd is Apples advertising framework, developers can use iAds for loading & presenting ads. Apple also enables developers to respond to the events in ads. One plus point of iAd is that when you tap on the ad in the application, the application will not exit to show you the ad in Safari, you will remain in the application & you can close the ad anytime you want. This is one big convenience when compared with other ad offering frameworks like Google’s Ad-Mob.

Game Center

Is a social networking gamming system something like OpenFeint. Now you can view achievements, compare them with your friends, view leader boards, find new games etc all of the stuff which you were able to do with OpenFeint is now possible with Game Center.

Core Motion

In addition to the accelerometer Apple has added the gyroscope to the iPhone 4. Now you can use the API in the Core Motion to take advantage of gyroscope & make your applications more interactive.

Core Foundation & Foundation additions

CF & NSFoundation has been brought to the snow leopard equivalence in iOS4, which includes the inclusion of Blocks & Regular Expressions to name a few.

Blocks

Here is a small introduction to Blocks to get your feet wet.

Blocks are self-contained units of work; they are similar to but far more powerful than traditional function pointers. Blocks are objects & they respond to NSObject methods. Here is a small example on blocks to get you started:-

Declaring a block variable:

void (^my_block)(void)); //first void is return type (^my_block) is the block declaration & the other void is the argument in the argument list.
Assigning a block object to it:

my_block = ^(void){ printf("hello world\n"); };
Invoking it:

my_block(); // prints “hello world\n”
Accepting a block as an argument:

- (void)doSomething:(void (^)(void))block;
Using that method with an inline block:

[obj doSomeThing:^(void){ printf(“block was called”); }];

Advertisements

One thought on “Apples iOS4 update What’s in it for the developers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s