Easily adopt Handoff for different types of activities.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Example
SPLUserActivity
.gitignore
LICENSE
SPLUserActivity.podspec
circle.yml
readme.md

readme.md

SPLUserActivity

Circle CI Coverage Status

Handoff is a powerful new feature in iOS 8 and OS X 10.10 that allows a user to begin an activity on one device and continue it on another device signed into the same iCloud account.

SPLUserActivity is a collection of objects that make it easy to adopt Handoff for different types of activities.

SPLUserActivity powers Handoff for the web browser in my app MUDRammer - A Modern MUD Client for iPhone and iPad.

SPLWebActivity

SPLWebActivity powers a Handoff activity for web browsing. It allows a user to continue browsing from the same web page on another device.

Examples

Check out Example for a simple app that displays a WKWebView and broadcasts a Handoff activity as the user browses between web pages. Note that Handoff won't function in the simulator - you'll need to run it on a device.

WKWebView

If your app uses a WKWebView, initialize a SPLWebActivity by passing your webview:

WKWebView *myWebView = ...

SPLWebActivity *webActivity = [SPLWebActivity activityWithWKWebView:myWebView];

That's it -- you're done! SPLWebActivity will start broadcasting a Handoff event right away. Thanks to the magic of KVO, SPLWebActivity will observe your WKWebView and will automatically update its activity URL and page title as the user navigates between web pages.

UIWebView

If your app uses a UIWebView, initialize a SPLWebActivity by passing your webview:

UIWebView *myWebView = ...

self.webActivity = [SPLWebActivity activityWithUIWebView:myWebView];

As with WKWebView, SPLWebActivity will begin broadcasting a Handoff event right away. However, UIWebView does not conform to KVO, so you'll need to tell SPLWebActivity to update itself as the user navigates between web pages:

#pragma mark - UIWebViewDelegate

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.webActivity setNeedsUpdate];
}

After receiving a setNeedsUpdate message, SPLWebActivity will query your UIWebView for the user's current URL and update its Handoff activity.

URLs

SPLWebActivity also allows your user to browse any URL on another device -- no webview required.

SPLWebActivity *myActivity = [SPLWebActivity activityWithURL:[NSURL URLWithString:@"http://splinesoft.net"]];

Continue Events

You may optionally specify a block that will be called when the user continues an activity on another device.

myActivity.activityContinuedBlock = ^{
	NSLog(@"I've just continued an activity!");
};

Cleanup

When your user activity is no longer relevant -- perhaps when your webview is popped off the navigation stack, or when the activity is no longer available -- make sure to invalidate the activity.

[myActivity invalidate];

An invalidated activity can no longer becomeCurrent and cannot be reused. If you'd like to broadcast a Handoff event again, create a new instance of SPLWebActivity.

Install

Install with CocoaPods. Add to your Podfile:

pod 'SPLUserActivity'

Thanks!

SPLUserActivity is a @jhersh production -- (electronic mail | @jhersh)