SlideShare a Scribd company logo
1 of 23
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).
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

Similar to Introduction to Handoff

Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Dr. Ramkumar Lakshminarayanan
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2Tadas Jurelevičius
 
Android application development
Android application developmentAndroid application development
Android application developmentMd. Mujahid Islam
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - AndroidWingston
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentMonir Zzaman
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1Hussain Behestee
 
Adopting 3D Touch in your apps
Adopting 3D Touch in your appsAdopting 3D Touch in your apps
Adopting 3D Touch in your appsJuan C Catalan
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2DHIRAJ PRAVIN
 
Android application model
Android application modelAndroid application model
Android application modelmagicshui
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android applicationNikunj Dhameliya
 
android activity
android activityandroid activity
android activityDeepa Rani
 

Similar to Introduction to Handoff (20)

Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2
 
Android application development
Android application developmentAndroid application development
Android application development
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Unit2
Unit2Unit2
Unit2
 
Data binding w Androidzie
Data binding w AndroidzieData binding w Androidzie
Data binding w Androidzie
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Adopting 3D Touch in your apps
Adopting 3D Touch in your appsAdopting 3D Touch in your apps
Adopting 3D Touch in your apps
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Android
AndroidAndroid
Android
 
Android application model
Android application modelAndroid application model
Android application model
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 
android activity
android activityandroid activity
android activity
 
Android Development Basics
Android Development BasicsAndroid Development Basics
Android Development Basics
 

More from Harit Kothari

Key areas for successful software delivery
Key areas for successful software deliveryKey areas for successful software delivery
Key areas for successful software deliveryHarit Kothari
 
Free & Open Source - an introduction
Free & Open Source - an introductionFree & Open Source - an introduction
Free & Open Source - an introductionHarit Kothari
 
OWASP Top 10 : Let’s know & solve
OWASP Top 10 : Let’s know & solveOWASP Top 10 : Let’s know & solve
OWASP Top 10 : Let’s know & solveHarit Kothari
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In PhpHarit Kothari
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In PhpHarit Kothari
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With MysqlHarit Kothari
 

More from Harit Kothari (9)

Key areas for successful software delivery
Key areas for successful software deliveryKey areas for successful software delivery
Key areas for successful software delivery
 
Basic Intro to iOS
Basic Intro to iOSBasic Intro to iOS
Basic Intro to iOS
 
Free & Open Source - an introduction
Free & Open Source - an introductionFree & Open Source - an introduction
Free & Open Source - an introduction
 
OWASP Top 10 : Let’s know & solve
OWASP Top 10 : Let’s know & solveOWASP Top 10 : Let’s know & solve
OWASP Top 10 : Let’s know & solve
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
 
Coding In Php
Coding In PhpCoding In Php
Coding In Php
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With Mysql
 
Starting With Php
Starting With PhpStarting With Php
Starting With Php
 

Recently uploaded

XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 

Recently uploaded (20)

XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 

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).
  • 6.
  • 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