Handoff Best Practices
Before you go, I thought I’d leave you with a few thoughts on Handoff best practices.
-
NSURL: Using
NSURL
in an NSUserActivity
userInfo
dictionary can be tricky. The only NSURL
s you can pass safely in Handoff are web site URLs that use HTTP or HTTPS and iCloud documents. You can’t pass local file URLs as the receiver won’t translate and map the URL properly at the receiver’s end. The best way to achieve file links is to pass a relative path and re-construct your URL on the receiving side.
-
Platform specific values: Avoid using platform specific values like the content offset of a scroll view; it’s always better to use relative landmarks. For example, if your user is viewing some items in a table view, pass the index path of the top most visible item in the table view in your user activity object instead of passing the content offset or visible rect of the table view.
-
Versioning: Think about using versioning and future-proofing updates of your app. You could add new data formats or remove values entirely from your
userInfo
dictionary in future versions of the app. Versioning gives you more control over how user activities are actioned in current and future versions of your app.
Where To Go From Here?
Here is the final example project that you developed in the above tutorial.
If you’re curious to learn more about Handoff, streaming, and document based Handoff, be sure to check out Apple’s Handoff Programming Guide for more information now that you know the basics.
If you enjoyed this tutorial, check out our book iOS 8 by Tutorials, which is chock-full of tutorials like this.
If you have any questions or comments about this tutorial, please join the forum discussion below!