During the last Apple presentation there were a lot of talks about a new Handoff feature. Its main purpose is to share information between different Apple devices using the same Apple ID. For example, starting to work on the iPad user might switch it to the Mac and continue doing the same task on another device.
There are a few technical requirements to use Handoff on your devices. Your computer must be running by OS X Yosemite, iPad, iPhone or iPod Touch should use iOS 8. Your devices should be listed in the same iCloud account and support Bluetooth 4.0 LE.
iOS developers might be interested to use Handoff features on their own applications. Handoff is based on the concept of User Activity. User Activity is independent piece of information and it can be freely transferred. Apple’s NSUserActivity class is the implementation of this concept, it represents the state of the application.
There are a few main components of NSUserActivity:
- ActivityType is an unique string identifier represented by Reverse DNS notation. For Example, «com.agilie.exampleapp.addFriends»
All activity types should be included in Info.plist configuration file.
- UserInfo is the dictionary to store application data. By this information the application will restore the state on another device. For example, we might store information about user friends. @ {" exampleapp.participants.key": @ [ «John Smith”, «Bill Jones", «Andy Robson"]}
UserInfo allows us to store native data types like NSArray, NSData, NSDate, NSDictionary, NSNull, NSNumber, NSSet, NSString, NSUUID, and NSURL.
Mobile application developers could implement a few methods to start use these components. Current UIViewController should start the activity by invocation of becomeCurrent()
method. To get periodically updates this UIViewController should overwrite the method updateUserActivityState (activity :)
The target device needs to handle the start by AppDelegate’s methods application: willContinueUserActivityWithType:
and application: continueUserActivity: restorationHandler:
The first method tells the application about user activity by some type and starts to load the data. The second method is called when the data from UserInfo is loaded and we can restore the state of the application.
As you can see Handoff implementation is quite simple and transparent. Our future experience in mobile apps developing will show if Handoff provides to the users the benefits or will remain as another cool but unpopular innovation from Apple.