Creating an NSUserActivity

suggest change

To create an NSUserActivity, declare the activity types your app supports in Info.plist. Each type is an identifier you define, in reverse-DNS form, such as com.companyName.productName.activityName. An NSUserActivityTypes entry looks like this:

After those types are declared, you can create an activity in code:

// Initialize the activity object and set its type from one of the ones specified in your app's plist
NSUserActivity *currentActivity = [[NSUserActivity alloc] initWithActivityType:@"com.companyName.productName.activityName01"];

// Set the title of the activity.
// This title may be displayed to the user, so make sure it is localized and human-readable
currentActivity.title = @"Current Activity";

// Configure additional properties like userInfo which will be included in the activity
currentActivity.userInfo = @{@"informationKey" : @"value"};

// Configure the activity so the system knows what may be done with it
// It is important that you only set YES to tasks that your application supports
// In this example, we will only enable the activity for use with Handoff
[currentActivity setEligibleForHandoff:YES];
[currentActivity setEligibleForSearch:NO]; // Defaults to NO
[currentActivity setEligibleForPublicIndexing:NO]; // Defaults to NO

// Set this activity as the current user activity
// Only one activity may be current at a time on a device. Calling this method invalidates any other current activities.
[currentActivity becomeCurrent];

Call becomeCurrent on the main thread. Only one activity is current at a time. The receiving device still has to continue the activity in its app delegate.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents