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.
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)
- VoIP (Voice over IP)
This is how application state is specified in the UIApplication.h header file
Illustrating that we have three application states on the iOS4.
- In Background
When the application is launched we will receive the usual message from the app delegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
In addition to this we will now also receive this message
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;
*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.
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.
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 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.
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.
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.
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:
For more information kindly visit: https://developer.apple.com
Article was originally published on 22 June 2010 on this link