<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSUserActivity",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUserActivity"
  },
  "title" : "NSUserActivity"
}
-->

# NSUserActivity

A representation of the state of your app at a moment in time.

```
class NSUserActivity
```

## Overview

The `NSUserActivity` class is a lightweight type that encapsulates the state of an activity you perform
in your app. When someone performs a relevant action in your app, create an instance of this class to
capture that activity. The system uses the user activity objects you provide to facilitiate features
like Handoff and Quick Notes. For example, Handoff sends your user activity object to the person’s
other devices so your app can replicate the activity there.

Create an `NSUserActivity` object and initialize it with the [`activityType`](/documentation/Foundation/NSUserActivity/activityType) string for
that particular activity. You define the activity types your app supports and create reverse-DNS strings
for each one in your code. Typically, activities correspond to actions that a person takes in your app’s
interface. For example, you might create one activity for viewing items and a separate activity for
completing edits to an item.

Add enough information to your user activity object to recreate the activity in your app at a later time.
If your activity has an associated URL, place it in the [`webpageURL`](/documentation/Foundation/NSUserActivity/webpageURL) property. If your
user activity object refers to a specific piece of your app’s content, specify the identifier for that
content using the [`targetContentIdentifier`](/documentation/Foundation/NSUserActivity/targetContentIdentifier), [`appEntityIdentifier`](/documentation/Foundation/NSUserActivity/appEntityIdentifier),
or [`externalMediaContentIdentifier`](/documentation/Foundation/NSUserActivity/externalMediaContentIdentifier) property. Place any other app-specific data in the
[`userInfo`](/documentation/Foundation/NSUserActivity/userInfo) dictionary. Provide a human-readable [`title`](/documentation/Foundation/NSUserActivity/title) for the activity,
and enable the features your activity supports such as Handoff and Spotlight indexing. Fill in other
properties as needed for your specific activity type.

Create user activity objects in response to specific interactions with your app’s interface. When someone
performs a significant task in your interface, create a user activity object and call its [`becomeCurrent()`](/documentation/Foundation/NSUserActivity/becomeCurrent())
method to make it your app’s current activity. For example, you might do this when someone opens a new
document in your app. Handoff and other features operate on the current activity and use it as context
for their behavior. In the case of opening a document, Handoff indicates that the person can open that
document on their other devices. When the person stops the activity in your interface, or the activity
is no longer relevant, call the [`resignCurrent()`](/documentation/Foundation/NSUserActivity/resignCurrent()) or [`invalidate()`](/documentation/Foundation/NSUserActivity/invalidate()) method, or create a new user
activity object and make it the current one.

For features like Handoff to work, the system needs to know which types of activities it can deliver to your
app. To specify the activity types you support, add the
<doc://com.apple.documentation/documentation/BundleResources/Information-Property-List/NSUserActivityTypes>
key to your app’s `Info.plist` file. Configure this key using the Info tab of your Xcode project, and set
its value to an array of strings. For each string, specify one of the activity types you use to create your
`NSUserActivity` objects. You can specify all of your app’s activity types or only a subset.

System features like Siri and Apple Intelligence use contextual information from your app’s interface to
improve their responses. Assign <doc://com.apple.documentation/documentation/AppIntents/AppEntity> types
directly to your views when possible, but you can also assign a user activity object to your view as needed.
In SwiftUI, create and configure this user activity object using the
<doc://com.apple.documentation/documentation/SwiftUI/View/userActivity(_:element:_:)> modifier.
In UIKit and AppKit, assign the user activity object to the <doc://com.apple.documentation/documentation/UIKit/UIResponder/userActivity>
property of a responder object in your interface. Use the [`appEntityIdentifier`](/documentation/Foundation/NSUserActivity/appEntityIdentifier) property
of your user activity object to provide the entity for your view.

## Topics

### Creating a user activity object

[`init(activityType:)`](/documentation/Foundation/NSUserActivity/init(activityType:))

Creates a user activity object with the specified type.

### Monitoring activity-related behaviors

[`delegate`](/documentation/Foundation/NSUserActivity/delegate)

The user activity object’s delegate.

[`NSUserActivityDelegate`](/documentation/Foundation/NSUserActivityDelegate)

The interface through which a user activity instance notifies its delegate of updates.

### Describing the activity

[`activityType`](/documentation/Foundation/NSUserActivity/activityType)

The user activity object’s activity type.

[`title`](/documentation/Foundation/NSUserActivity/title)

An optional, user-visible title for this activity, such as a document name or web page title.

[`keywords`](/documentation/Foundation/NSUserActivity/keywords)

A set of localized keywords that can help users find the activity in search results.

[`persistentIdentifier`](/documentation/Foundation/NSUserActivity/persistentIdentifier)

A unique and persistent value you use to identify the activity.

[`NSUserActivityPersistentIdentifier`](/documentation/Foundation/NSUserActivityPersistentIdentifier)

The type that defines a persistent identifier value for an activity.

[`contentAttributeSet`](/documentation/Foundation/NSUserActivity/contentAttributeSet)

A set of properties that describe the activity.

### Enabling system behaviors

[`isEligibleForHandoff`](/documentation/Foundation/NSUserActivity/isEligibleForHandoff)

A Boolean value that indicates whether the activity can continue on another device using Handoff.

[`isEligibleForSearch`](/documentation/Foundation/NSUserActivity/isEligibleForSearch)

A Boolean value that indicates whether to add the activity to the on-device index.

[`isEligibleForPublicIndexing`](/documentation/Foundation/NSUserActivity/isEligibleForPublicIndexing)

A Boolean value that indicates whether the activity is publicly accessible by all iOS users.

[`isEligibleForPrediction`](/documentation/Foundation/NSUserActivity/isEligibleForPrediction)

A Boolean value that determines whether Siri can suggest the activity as a shortcut.

[`expirationDate`](/documentation/Foundation/NSUserActivity/expirationDate)

The date after which the activity is no longer eligible for Handoff or indexing.

### Specifying app identifiers

[`appEntityIdentifier`](/documentation/Foundation/NSUserActivity/appEntityIdentifier)

The identifier of an app entity that you associate with the user activity.

[`targetContentIdentifier`](/documentation/Foundation/NSUserActivity/targetContentIdentifier)

A string that identifies the user activity’s content.

[`externalMediaContentIdentifier`](/documentation/Foundation/NSUserActivity/externalMediaContentIdentifier)

A unique identifier from the app’s media content catalog for the currently displayed media item.

### Browsing the web

[`webpageURL`](/documentation/Foundation/NSUserActivity/webpageURL)

The URL of the webpage to load in a browser to continue the activity.

[`referrerURL`](/documentation/Foundation/NSUserActivity/referrerURL)

The URL of the webpage that linked to the webpage URL.

[`NSUserActivityTypeBrowsingWeb`](/documentation/Foundation/NSUserActivityTypeBrowsingWeb)

An activity that continues from Handoff or a universal link.

  <doc://com.apple.documentation/documentation/TVServices/TVUserActivityTypeBrowsingChannelGuide>

### Specifying activity-related data

[`userInfo`](/documentation/Foundation/NSUserActivity/userInfo)

A dictionary containing app-specific state information needed to continue an activity on another device.

[`addUserInfoEntries(from:)`](/documentation/Foundation/NSUserActivity/addUserInfoEntries(from:))

Adds the contents of the specified dictionary to the user info dictionary.

[`requiredUserInfoKeys`](/documentation/Foundation/NSUserActivity/requiredUserInfoKeys)

A set of keys that represent the minimal information about the activity that should be stored for later restoration.

### Accessing feature-specific data

[`appClipActivationPayload`](/documentation/Foundation/NSUserActivity/appClipActivationPayload)

An object containing the payload information that launches an App Clip.

[`detectedBarcodeDescriptor`](/documentation/Foundation/NSUserActivity/detectedBarcodeDescriptor)

The barcode that the system scanner passes in.

[`mapItem`](/documentation/Foundation/NSUserActivity/mapItem)

Attaches the specified map item to a user activity object.

[`ndefMessagePayload`](/documentation/Foundation/NSUserActivity/ndefMessagePayload)

The NDEF message read by the system in the background.

[`isClassKitDeepLink`](/documentation/Foundation/NSUserActivity/isClassKitDeepLink)

A Boolean value that indicates whether a user activity represents a ClassKit context.

[`contextIdentifierPath`](/documentation/Foundation/NSUserActivity/contextIdentifierPath)

The identifier path associated with a user activity generated by an app that adopts ClassKit.

[`widgetConfigurationIntent(of:)`](/documentation/Foundation/NSUserActivity/widgetConfigurationIntent(of:))

### Registering and invalidating activities

[`becomeCurrent()`](/documentation/Foundation/NSUserActivity/becomeCurrent())

Marks the activity as currently in use by the user.

[`resignCurrent()`](/documentation/Foundation/NSUserActivity/resignCurrent())

Marks this activity object as inactive without invalidating it.

[`invalidate()`](/documentation/Foundation/NSUserActivity/invalidate())

Invalidates an activity and marks it as no longer eligible for continuation.

[`needsSave`](/documentation/Foundation/NSUserActivity/needsSave)

A Boolean value that indicates whether the state of the activity needs to be updated.

[`deleteAllSavedUserActivities(completionHandler:)`](/documentation/Foundation/NSUserActivity/deleteAllSavedUserActivities(completionHandler:))

Deletes all user activities created by your app.

[`deleteSavedUserActivities(withPersistentIdentifiers:completionHandler:)`](/documentation/Foundation/NSUserActivity/deleteSavedUserActivities(withPersistentIdentifiers:completionHandler:))

Deletes user activities created by your app that have the specified persistent identifiers.

### Managing type-safe access to user info

[`setTypedPayload(_:)`](/documentation/Foundation/NSUserActivity/setTypedPayload(_:))

Encodes the specified payload into the user activity’s user info dictionary.

[`typedPayload(_:)`](/documentation/Foundation/NSUserActivity/typedPayload(_:))

Decodes the user activity’s user info dictionary as an instance of the specified type.

[`NSUserActivity.TypedPayloadError`](/documentation/Foundation/NSUserActivity/TypedPayloadError)

An enumeration that describes the error types for getting and setting a typed payload.

### Working with continuation streams

[`supportsContinuationStreams`](/documentation/Foundation/NSUserActivity/supportsContinuationStreams)

A Boolean value that determines whether the continuing app can request streams to be opened back to the originating app.

[`getContinuationStreams(completionHandler:)`](/documentation/Foundation/NSUserActivity/getContinuationStreams(completionHandler:))

Requests streams back to the originating app.

### Providing SiriKit with activity details

[`interaction`](/documentation/Foundation/NSUserActivity/interaction)

The SiriKit interaction object to use when configuring your app.

[`suggestedInvocationPhrase`](/documentation/Foundation/NSUserActivity/suggestedInvocationPhrase)

A phrase suggested to the user when they create a shortcut.

[`shortcutAvailability`](/documentation/Foundation/NSUserActivity/shortcutAvailability)

A set of defined contexts in which an intent or activity might be relevant to a user.

### Reporting errors

[`NSUserActivityConnectionUnavailableError`](/documentation/Foundation/NSUserActivityConnectionUnavailableError-swift.var)

The user activity couldn’t be continued because a required connection wasn’t available.

[`NSUserActivityErrorMaximum`](/documentation/Foundation/NSUserActivityErrorMaximum-swift.var)

The end of the range of error codes reserved for user activity errors.

[`NSUserActivityErrorMinimum`](/documentation/Foundation/NSUserActivityErrorMinimum-swift.var)

The start of the range of error codes reserved for user activity errors.

[`NSUserActivityHandoffFailedError`](/documentation/Foundation/NSUserActivityHandoffFailedError-swift.var)

The data for the user activity wasn’t available.

[`NSUserActivityHandoffUserInfoTooLargeError`](/documentation/Foundation/NSUserActivityHandoffUserInfoTooLargeError-swift.var)

The user info dictionary was too large to receive.

[`NSUserActivityRemoteApplicationTimedOutError`](/documentation/Foundation/NSUserActivityRemoteApplicationTimedOutError-swift.var)

The remote application failed to send data within the specified time.

[`NSUserActivityConnectionUnavailableError`](/documentation/Foundation/NSUserActivityConnectionUnavailableError-c.enum.case)

The user activity couldn’t be continued because a required connection wasn’t available.

[`NSUserActivityErrorMaximum`](/documentation/Foundation/NSUserActivityErrorMaximum-c.enum.case)

The end of the range of error codes reserved for user activity errors.

[`NSUserActivityErrorMinimum`](/documentation/Foundation/NSUserActivityErrorMinimum-c.enum.case)

The start of the range of error codes reserved for user activity errors.

[`NSUserActivityHandoffFailedError`](/documentation/Foundation/NSUserActivityHandoffFailedError-c.enum.case)

The data for the user activity wasn’t available.

[`NSUserActivityHandoffUserInfoTooLargeError`](/documentation/Foundation/NSUserActivityHandoffUserInfoTooLargeError-c.enum.case)

The user info dictionary was too large to receive.

[`NSUserActivityRemoteApplicationTimedOutError`](/documentation/Foundation/NSUserActivityRemoteApplicationTimedOutError-c.enum.case)

The remote application failed to send data within the specified time.

### Deprecated

[`init()`](/documentation/Foundation/NSUserActivity/init())

Creates a user activity object using the first activity type declared in the app’s information property list file.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)