SlideShare a Scribd company logo
Introduction to
Handoff
Harit Kothari
@harit
Handoff
Also known as Continuity
Handoff is a new capability in iOS 8 and OS X v10.10 that is
designed to facilitate easy transfer of user activities among
multiple devices associated with the same user.
In other words
Handoff provides seamless user activity across device/apps
signed with identical identifier
Applications
User collaboration
Task scalability across devices / platforms (limited
to Apple, of course)
Accessing phone calls & SMS of phone through
Mac/OS X
Requirements
Bluetooth LE (v4.0)
Signed into identical iCloud account
Devices need to be in close physical proximity
Internet connectivity (assumption)
iOS 8 and/or OSX 10.10.x+
Compatibility
Will work with –
 iPhone 5 or later
 iPad (4th gen)
 iPad Air
 iPad mini
 iPad mini - Retina display
 iPod touch (5th gen).
Introduction to Handoff
NSUserActivity
 @property (strong) NSUserActivity *userActivity;
 myActivity = [[NSUserActivity alloc] initWithActivityType:
@"com.myCompany.myBrowser.browsing"];
myActivity.userInfo = @{};
myActivity.title = @"Browsing”;
[myActivity becomeCurrent];
Allowed types of userInfo – payload : NSArray,
NSData, NSDate, NSDictionary, NSNull,
NSNumber, NSSet, NSString, NSUUID, NSURL
NSUserActivity
Major methods
 becomeCurrent
 Invalidate
Document based app
 For basic need, have to set:
 CFBundleDocumentTypes (of type Array) under Document
types key
 NSUbiquitousDocumentUserActivityType key with value - string
used for the NSUserActivity object’s activity type - reverse-DNS
app designator with the name of the activity (append if more)
Document based app
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key> <!– name of document type -->
<string>NSRTFDPboardType</string> <key>LSItemContentTypes</key> <!–
supported file types -->
<array>
<string>com.myCompany.rtfd</string>
</array>
<key>NSUbiquitousDocumentUserActivityType</key> <!– activity name in
reverse DNS notation --> <string>com.myCompany.myEditor.editing</string>
</dict>
</array>
Create Activity
NSUserActivity *currentActivity = [self userActivity];
NSString *bundleName = [[NSBundle mainBundle] bundleIdentifier];
NSString *myActivityType = [bundleName stringByAppendingString: @".selected-list"];
if( ![[currentActivity activityType] isEqualToString:myActivityType] )
{
[currentActivity invalidate];
currentActivity = [[NSUserActivity alloc] initWithActivityType:myActivityType];
[currentActivity setDelegate:self];
[currentActivity setNeedsSave:YES];
[self setUserActivity:currentActivity];
}
Else
{
[currentActivity setNeedsSave:YES];
}
Process Activity (1/2)
Application level handling
AppDelegate (NS/UIApplicationDelegate) – the
entry/resume point
- (BOOL) application:(UIApplication *)application willContinueUserActivityWithType:(NSString
*)userActivityType
{
return YES; // when continued successfully; return NO, otherwise
}
- (void) application:(UIApplication *)application didFailToContinueUserActivityWithType:(NSString
*)userActivityType error:(NSError *)error
{
// If there’s success, there’s failure
}
- (void)application:(UIApplication *)application didUpdateUserActivity:(NSUserActivity *)userActivity
{
// When a user activity managed by UIKit has been updated. Use this as a last chance to add
additional data to the userActivity.
}
Process Activity (2/2)
Application level handling
When the application is aware of possible activity (or /ties) – like document base:
- (BOOL)application:(UIApplication *)application continueUserActivity: (NSUserActivity
*)userActivity restorationHandler: (void(^)(NSArray *restorableObjects)) restorationHandler
{
NSString *activityType = userActivity.activityType;
if ([activityType isEqual:@"com.company.viewing-message"])
{
id vc = [[ViewController alloc] init];
- restorationHandler(@[vc]);
return YES;
}
return NO;
}
If above method is unimplemented or returns NO (typically in Document based
app), it is handled by:
- (void)restoreUserActivityState:(NSUserActivity *)activity
NSUserActivityDelegate (1/2)
- (void)userActivityWasContinued: (NSUserActivity *) userActivity
{
// The user activity will be saved (to be continued). Receiver should update its
activity object with current activity state (received from other device).
}
- (void)userActivityWillSave: (NSUserActivity *) userActivity
{
// User activity was continued on another device.
}
NSUserActivityDelegate (2/2)
- (void)userActivity: (NSUserActivity *)userActivity
didReceiveInputStream:(NSInputStream *)inputStream
outputStream:(NSOutputStream *)outputStream
{
// If supportsContinuationStreams is set to YES the continuing side can
request streams back to this user activity. This delegate callback will be received
with the incoming streams from the other side. The streams will be in an
unopened state. The streams should be opened immediately to start receiving
requests from the continuing side.
}
NSStream
NSInputStream provides read-only access to
stream data
NSOutputStream provides write-only access
Data written to the output stream on the originating
side is read from the input stream on the continuing
side, and vice versa
Streams are meant to be used in a request-and-
response fashion; that is
supportsContinuationStreams
activity.supportsContinuationStreams = YES;
- (BOOL)application: (UIApplication *)application continueUserActivity: (NSUserActivity
*)userActivity restorationHandler: (void(^)(NSArray
*restorableObjects))restorationHandler
{
[userActivity getContinuationStreamsWithCompletionHandler: ^(NSInputStream
*inputStream, NSOutputStream *outputStream, NSError *error)
{
// Do something with the streams
}];
return YES;
}
Summary (1/2)
 NSUserActivity class object is in core of this framework, which holds data
about user activity.
 The object instance is passively shared across apps and/or devices to provide
capability of continuing a task (or more) to the user.
 The application is required and responsible to handle NSUserActivity object
and delegate methods / callbacks to provide continuous activity.
 If payload (data) is heavy, use stream instead of userInfo.
Summary (2/2)
NSDocument or UIDocument based apps are said to
be able to handle Handoff automatically
Simplest example is browsing a webpage at
particular scroll position in iPad and then user
wants to switch to iPhone. With handoff it is
possible to show the same webpage with scroll
position on smaller screen/iPhone.
Tips from Apple (1/3)
 Design to transfer as small a payload as possible; the more payload data
you deliver, the longer it takes the activity to resume.
 When a large amount of data transfer is unavoidable, use streams, but
recognize that they have a cost in terms of network setup and overhead.
 Plan for different versions of apps on different platforms to work well
with each other or fail gracefully. Remember that the complementary
app design can be asymmetrical—for example, a monolithic Mac app
can route each of its activity types to smaller, special-purpose apps on
iOS.
Tips from Apple (2/3)
Use reverse-DNS notation for your activity types to
avoid collisions. If the activity pertains only to a
single app, you can use the app identifier with an
extra field appended to describe the activity type.
For example, use a format such as
com.<company>.<app>.<activity type>, as in
com.myCompany.myEditor.editing. If you have a
user activity that works across more than one app,
you can drop the app field, as in
com.myCompany.editing.
Tips from Apple (3/3)
To update the activity object’s userInfo dictionary
efficiently, configure its delegate and set its needsSave
property to YES whenever the userInfo needs updating.
At appropriate times, Handoff invokes the delegate’s
userActivityWillSave: callback, and the delegate can
update the activity state.
Be sure the delegate of the continuing app implements
its application:willContinueUserActivityWithType: to let
the user know the activity will be continued. The user
activity object may not be available instantly.
Thank you!
Further scope of study:
 Browser to Native App Handoff and vice versa
 Document based apps

More Related Content

PDF
Distributing information on iOS
PDF
Windows phone 7 series
DOCX
Creating EPiServer Usage Reports
PPT
Introduction to the INTEGRAL FRAMEWORK
PPT
Introduction to the integral framework
PPTX
How To Utilize Context API With Class And Functional Componen in React.pptx
PDF
SquiDB: a SQLite layer for Android - Jonathan Koren, Yahoo!
PDF
[@NaukriEngineering] Flux Architecture
Distributing information on iOS
Windows phone 7 series
Creating EPiServer Usage Reports
Introduction to the INTEGRAL FRAMEWORK
Introduction to the integral framework
How To Utilize Context API With Class And Functional Componen in React.pptx
SquiDB: a SQLite layer for Android - Jonathan Koren, Yahoo!
[@NaukriEngineering] Flux Architecture

Similar to Introduction to Handoff (20)

PPTX
Apple continuity
PDF
Introduction to iOS 9 (Xamarin Evolve 2016)
PDF
Iphone app programming guide
PDF
MFF UK - Advanced iOS Topics
PDF
AfNetworking vs. Native + Caching
PDF
Community App for Promoting Cross-Cultural Interaction
PDF
Community App for Promoting Cross-Cultural Interaction
ZIP
iPhone and Rails integration
PPTX
iOS Human Interface Guidelines (HCI)
PDF
iOS Human Interface Guidlines for iOS-Platforms
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
PPTX
Cross platform mobile development in c#
PPTX
iOS app dev Training - Session1
PDF
HCI Guidelines for iOS Platforms
PDF
Apple iPhone App Programming Guide
PPTX
iPhone Development For Experienced Web Developers
PDF
Certificato Corso iOS Essentials S7
PDF
Application for Data Sync Between Different geo Locations
PDF
Workflow automation i phone application for a construction company
PPTX
iOS Development (Part 2)
Apple continuity
Introduction to iOS 9 (Xamarin Evolve 2016)
Iphone app programming guide
MFF UK - Advanced iOS Topics
AfNetworking vs. Native + Caching
Community App for Promoting Cross-Cultural Interaction
Community App for Promoting Cross-Cultural Interaction
iPhone and Rails integration
iOS Human Interface Guidelines (HCI)
iOS Human Interface Guidlines for iOS-Platforms
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
Cross platform mobile development in c#
iOS app dev Training - Session1
HCI Guidelines for iOS Platforms
Apple iPhone App Programming Guide
iPhone Development For Experienced Web Developers
Certificato Corso iOS Essentials S7
Application for Data Sync Between Different geo Locations
Workflow automation i phone application for a construction company
iOS Development (Part 2)
Ad

More from Harit Kothari (9)

PPTX
Key areas for successful software delivery
PPTX
Basic Intro to iOS
ODP
Free & Open Source - an introduction
PPT
OWASP Top 10 : Let’s know & solve
ODP
Form Processing In Php
ODP
Session Management & Cookies In Php
ODP
Coding In Php
ODP
Database Connection With Mysql
ODP
Starting With Php
Key areas for successful software delivery
Basic Intro to iOS
Free & Open Source - an introduction
OWASP Top 10 : Let’s know & solve
Form Processing In Php
Session Management & Cookies In Php
Coding In Php
Database Connection With Mysql
Starting With Php
Ad

Recently uploaded (20)

PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Transform Your Business with a Software ERP System
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Understanding Forklifts - TECH EHS Solution
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Digital Strategies for Manufacturing Companies
PDF
Design an Analysis of Algorithms I-SECS-1021-03
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
L1 - Introduction to python Backend.pptx
Operating system designcfffgfgggggggvggggggggg
How Creative Agencies Leverage Project Management Software.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Odoo Companies in India – Driving Business Transformation.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Reimagine Home Health with the Power of Agentic AI​
Transform Your Business with a Software ERP System
Upgrade and Innovation Strategies for SAP ERP Customers
Odoo POS Development Services by CandidRoot Solutions
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Wondershare Filmora 15 Crack With Activation Key [2025
Understanding Forklifts - TECH EHS Solution
2025 Textile ERP Trends: SAP, Odoo & Oracle
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Digital Strategies for Manufacturing Companies
Design an Analysis of Algorithms I-SECS-1021-03

Introduction to Handoff

  • 2. Handoff Also known as Continuity Handoff is a new capability in iOS 8 and OS X v10.10 that is designed to facilitate easy transfer of user activities among multiple devices associated with the same user. In other words Handoff provides seamless user activity across device/apps signed with identical identifier
  • 3. Applications User collaboration Task scalability across devices / platforms (limited to Apple, of course) Accessing phone calls & SMS of phone through Mac/OS X
  • 4. Requirements Bluetooth LE (v4.0) Signed into identical iCloud account Devices need to be in close physical proximity Internet connectivity (assumption) iOS 8 and/or OSX 10.10.x+
  • 5. Compatibility Will work with –  iPhone 5 or later  iPad (4th gen)  iPad Air  iPad mini  iPad mini - Retina display  iPod touch (5th gen).
  • 7. NSUserActivity  @property (strong) NSUserActivity *userActivity;  myActivity = [[NSUserActivity alloc] initWithActivityType: @"com.myCompany.myBrowser.browsing"]; myActivity.userInfo = @{}; myActivity.title = @"Browsing”; [myActivity becomeCurrent]; Allowed types of userInfo – payload : NSArray, NSData, NSDate, NSDictionary, NSNull, NSNumber, NSSet, NSString, NSUUID, NSURL
  • 9. Document based app  For basic need, have to set:  CFBundleDocumentTypes (of type Array) under Document types key  NSUbiquitousDocumentUserActivityType key with value - string used for the NSUserActivity object’s activity type - reverse-DNS app designator with the name of the activity (append if more)
  • 10. Document based app <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeName</key> <!– name of document type --> <string>NSRTFDPboardType</string> <key>LSItemContentTypes</key> <!– supported file types --> <array> <string>com.myCompany.rtfd</string> </array> <key>NSUbiquitousDocumentUserActivityType</key> <!– activity name in reverse DNS notation --> <string>com.myCompany.myEditor.editing</string> </dict> </array>
  • 11. Create Activity NSUserActivity *currentActivity = [self userActivity]; NSString *bundleName = [[NSBundle mainBundle] bundleIdentifier]; NSString *myActivityType = [bundleName stringByAppendingString: @".selected-list"]; if( ![[currentActivity activityType] isEqualToString:myActivityType] ) { [currentActivity invalidate]; currentActivity = [[NSUserActivity alloc] initWithActivityType:myActivityType]; [currentActivity setDelegate:self]; [currentActivity setNeedsSave:YES]; [self setUserActivity:currentActivity]; } Else { [currentActivity setNeedsSave:YES]; }
  • 12. Process Activity (1/2) Application level handling AppDelegate (NS/UIApplicationDelegate) – the entry/resume point - (BOOL) application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType { return YES; // when continued successfully; return NO, otherwise } - (void) application:(UIApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error { // If there’s success, there’s failure } - (void)application:(UIApplication *)application didUpdateUserActivity:(NSUserActivity *)userActivity { // When a user activity managed by UIKit has been updated. Use this as a last chance to add additional data to the userActivity. }
  • 13. Process Activity (2/2) Application level handling When the application is aware of possible activity (or /ties) – like document base: - (BOOL)application:(UIApplication *)application continueUserActivity: (NSUserActivity *)userActivity restorationHandler: (void(^)(NSArray *restorableObjects)) restorationHandler { NSString *activityType = userActivity.activityType; if ([activityType isEqual:@"com.company.viewing-message"]) { id vc = [[ViewController alloc] init]; - restorationHandler(@[vc]); return YES; } return NO; } If above method is unimplemented or returns NO (typically in Document based app), it is handled by: - (void)restoreUserActivityState:(NSUserActivity *)activity
  • 14. NSUserActivityDelegate (1/2) - (void)userActivityWasContinued: (NSUserActivity *) userActivity { // The user activity will be saved (to be continued). Receiver should update its activity object with current activity state (received from other device). } - (void)userActivityWillSave: (NSUserActivity *) userActivity { // User activity was continued on another device. }
  • 15. NSUserActivityDelegate (2/2) - (void)userActivity: (NSUserActivity *)userActivity didReceiveInputStream:(NSInputStream *)inputStream outputStream:(NSOutputStream *)outputStream { // If supportsContinuationStreams is set to YES the continuing side can request streams back to this user activity. This delegate callback will be received with the incoming streams from the other side. The streams will be in an unopened state. The streams should be opened immediately to start receiving requests from the continuing side. }
  • 16. NSStream NSInputStream provides read-only access to stream data NSOutputStream provides write-only access Data written to the output stream on the originating side is read from the input stream on the continuing side, and vice versa Streams are meant to be used in a request-and- response fashion; that is
  • 17. supportsContinuationStreams activity.supportsContinuationStreams = YES; - (BOOL)application: (UIApplication *)application continueUserActivity: (NSUserActivity *)userActivity restorationHandler: (void(^)(NSArray *restorableObjects))restorationHandler { [userActivity getContinuationStreamsWithCompletionHandler: ^(NSInputStream *inputStream, NSOutputStream *outputStream, NSError *error) { // Do something with the streams }]; return YES; }
  • 18. Summary (1/2)  NSUserActivity class object is in core of this framework, which holds data about user activity.  The object instance is passively shared across apps and/or devices to provide capability of continuing a task (or more) to the user.  The application is required and responsible to handle NSUserActivity object and delegate methods / callbacks to provide continuous activity.  If payload (data) is heavy, use stream instead of userInfo.
  • 19. Summary (2/2) NSDocument or UIDocument based apps are said to be able to handle Handoff automatically Simplest example is browsing a webpage at particular scroll position in iPad and then user wants to switch to iPhone. With handoff it is possible to show the same webpage with scroll position on smaller screen/iPhone.
  • 20. Tips from Apple (1/3)  Design to transfer as small a payload as possible; the more payload data you deliver, the longer it takes the activity to resume.  When a large amount of data transfer is unavoidable, use streams, but recognize that they have a cost in terms of network setup and overhead.  Plan for different versions of apps on different platforms to work well with each other or fail gracefully. Remember that the complementary app design can be asymmetrical—for example, a monolithic Mac app can route each of its activity types to smaller, special-purpose apps on iOS.
  • 21. Tips from Apple (2/3) Use reverse-DNS notation for your activity types to avoid collisions. If the activity pertains only to a single app, you can use the app identifier with an extra field appended to describe the activity type. For example, use a format such as com.<company>.<app>.<activity type>, as in com.myCompany.myEditor.editing. If you have a user activity that works across more than one app, you can drop the app field, as in com.myCompany.editing.
  • 22. Tips from Apple (3/3) To update the activity object’s userInfo dictionary efficiently, configure its delegate and set its needsSave property to YES whenever the userInfo needs updating. At appropriate times, Handoff invokes the delegate’s userActivityWillSave: callback, and the delegate can update the activity state. Be sure the delegate of the continuing app implements its application:willContinueUserActivityWithType: to let the user know the activity will be continued. The user activity object may not be available instantly.
  • 23. Thank you! Further scope of study:  Browser to Native App Handoff and vice versa  Document based apps