Handoff User Guide, handoff cannot be used

Source: Internet
Author: User

Handoff User Guide, handoff cannot be used
Handoff Introduction

Handoff is a feature introduced in iOS 8 and OS X v10.10. It allows the same user to transmit projects between multiple devices. In iOS 9 and OS X v10.11 supports searching and opening applications In Spotlight.

Handoff Interaction:

In iOS, this user activity object is inNSUserActivity class.

Hard conditions required by Handoff:

  • All connected devices must support Buletooth LE 4.0. Handoff uses BLE signals to transmit user activity data.

  • All devices must be connected to the same iCloud account.

  • Of course, you must ensure that the Handoff function of the current device is enabled (iOS: settings-> General-> Handoff and recommended applications. Mac: system preference settings-> General, the penultimate column has an option, "allow Handoff between this Mac and iCloud devices ")

BLE is not like the traditional Bluetooth, and does not need to be manually paired. As long as it is enabled, all the paired data transmission is completed automatically; devices do not necessarily need to be connected to the same Wi-Fi network. The basic data of Handoff activities is transmitted through BLE, and large data is synchronized through iCloud (streams through the network, for example, there is an image in the email ).

Workflow

The core class of Handoff programming is NSUserActivity, which represents a user Activity. Each Activity has an activityType to identify the Activity type. When Handoff is performed between apps, the following conditions must be met:

  • Log On with the same Apple ID in iCloud
  • The same TeamID as the App that publishes the Activity.

  • Add the activity identifier NSUserActivityTypes to the Info. plist file of the Target that you want to support in the application.

Third-party APPs must be published through app Store or signed by registered developers. The Handoff app is started. during use, the Handoff message is distributed through BLE. After receiving the message, the iOS device checks whether the app has the same TeamID and NSUserActivityTypes as the start app, if yes, the recommendation app is displayed on the "another" device.

User Activity object

NSUserActivity objects store user activity information to continue working on different devices. The starting app must explicitly call becomeCurrent or Document-based apps to enable the Handoff function when you set the NSUserActivity object of the file for the UIViewController object at the view level when entering the foreground. Set the NSUserActivity object of the resignCurrent or Document-based app to nil disabled.

The unique identifier of the NSUserActivity object isactivityTypeAndtitleAttribute (document name or web page title ). Through eligibleForSearch,keywordsAndcontentAttributeSetAttribute support, so that its app can be displayed in Spotlight search results. PassExpirationDate specifies the expiration time.

The NSUserActivity object passes throughuserInfoTo store and share data information.

User Activity synchronization mechanism

There are two synchronization mechanisms for User Activity: lazy updating and system management.

  • Lazy updating
    • When the number of users to be synchronized is updatedSet the needsSave attribute to YES.
    • NSUserActivityBefore data is shareduserActivityWillSave:Method (NSUserActivityDelegate ).NSUserActivityMethodaddUserInfoEntriesFromDictionary:Method merge-related status informationuserInfoObject. After this method is called, The system resets the needsSave attribute to NO.
  • System Management
    • When the responder knows that the activity status has been modified, it must be setSet needsSave to YES(When the responder knows that the activity state is dirty, it must set the object'sneedsSavePropertyYES.). The system automatically synchronizes data at the appropriate time.NSUserActivityObject.UpdateUserActivityState: calls back to the responder to update the activity's state. Your responder subclass must override updateUserActivityState: Method to add status data to the user activity object (in this methodNSUserActivityMethodaddUserInfoEntriesFromDictionary:Method merge-related status informationUserInfo object). If multiple contacts share an NSUserActivity object, when the system updates the user activity object, they will receive the updateUserActivityState: callback. Before the update callback is sent, the userInfo Dictionary of the activity object is cleared.
Use App Delegate to continue using the activity

When a non-document app starts the responder app through Handoff, it will receive application: willContinueUserActivityWithType: And application: continueUserActivity: restorationHandler: messages in app delegate, which can be processed in four situations:

  • If you need other responders or file objects to restore the user activity, you need to call the block, the array includes the UIResponder set, and then each object receivesrestoreUserActivityState:Message.
  • If your ongoing activity is from the search list, you can reset the keyword here.
  • If application: continueUserActivity: restorationHandler: is not implemented or NO is returned, and the app is file-based, AppKit can automatically restore the default NSUserActivity object. In this case, the file will be opened using the NSDocumentController method openDocumentWithContentsOfURL: display: completionHandler:, and a restoreUserActivityState: message will be received.
  • File-based Apps support User Activity 

    If CFBundleDocumentTypes is added to the file-based app Info. plist, the Handoff function is supported by default. The string corresponding to NSUbiquitousDocumentUserActivityType serves as the activity type of the NSUserActivity object. Files are synchronized Based on iCloud and automatically generated and stored in the fileURL attribute. If the app delegate Method application: continueUserActivity: restorationHandler: NO is returned, or it is not implemented, then, AppKit can automatically restore the NSUserActivity object created in the preceding method. In this case, the file will be opened using the NSDocumentController method openDocumentWithContentsOfURL: display: completionHandler:, and a restoreUserActivityState: message will be received.

    Summary

    Handoff enables continuous interaction between devices after ios8.UIDocumentThe file app (Info. plist implements CFBundleDocumentTypes) supports the Handoff function by default. Non-file apps need to implement NSUserActivityTypes in Info. plist, which can be divided into two synchronization mechanisms: laze and system management. Some of the blogs I read said that it is not necessary to connect to the same network. You can use the default app provided by apple to test the function. (If you access Safari on Mac, you will be prompted to disable wifi on your mobile phone)

    There are three methods for reminding the app icon in the lower left corner of the iphone. Handoff is only one of them. I will introduce three methods separately, but they are different.

    References

    Https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Handoff/HandoffFundamentals/HandoffFundamentals.html#//apple_ref/doc/uid/TP40014338-CH3-SW1

     

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.