<!--
{
  "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

An [`NSUserActivity`](/documentation/Foundation/NSUserActivity) object provides a lightweight way to capture the state of your app and put it to use later. Create this object to capture information about what a person was doing, such as viewing app content, editing a document, viewing a web page, or watching a video. When the system launches your app and an activity object is available, your app can use the information in that object to restore itself to an appropriate state. Spotlight also uses these objects to improve search results for people. To allow people to continue an activity on another device, see [Implementing Handoff in Your App](/documentation/Foundation/implementing-handoff-in-your-app).

### Siri

If SiriKit needs to launch your app for any reason, it creates a user activity object and assigns an appropriate <doc://com.apple.documentation/documentation/Intents/INInteraction> object to its [`interaction`](/documentation/Foundation/NSUserActivity/interaction) property. Your app can use the interaction information to configure itself and display information related to the interaction started by SiriKit. You can also provide SiriKit with a custom user activity object containing additional data that you want passed to your app.

In iOS 15 and later, a person can share content they’re viewing by asking Siri to “share this”. Apps built with Mac Catalyst provide the same capability with an <doc://com.apple.documentation/documentation/AppKit/NSSharingServicePickerToolbarItem> in the toolbar. You can use <doc://com.apple.documentation/documentation/UIKit/UIActivityItemsConfigurationProviding/activityItemsConfiguration> or <doc://com.apple.documentation/documentation/UIKit/UIWindowScene/activityItemsConfigurationSource> to provide shareable content. In iOS, if both of those properties are <doc://com.apple.documentation/documentation/ObjectiveC/nil-227m0>, Siri uses the [`webpageURL`](/documentation/Foundation/NSUserActivity/webpageURL) property of your app’s current user activity as a fallback value.

### Quick Note

Quick Note on macOS and iOS can link to any app content represented as an [`NSUserActivity`](/documentation/Foundation/NSUserActivity). To appear as a link, the content must be the app’s current activity, and provide at least one of the following identifiers:

- term ``doc://com.apple.foundation/documentation/Foundation/NSUserActivity/webpageURL``: An `https:` URL, ideally in a canonical form that’s consistent every time a person visits the same content.
- term ``doc://com.apple.foundation/documentation/Foundation/NSUserActivity/persistentIdentifier``: A string that uniquely identifies the content in this domain. The identifier should identify the same content across devices.
- term ``doc://com.apple.foundation/documentation/Foundation/NSUserActivity/targetContentIdentifier``: A string that uniquely identifies the content in this domain, but also allows disambiguating between multiple scenes of an app. The identifier should identify the same content across devices.

To work well with Quick Note, content must adhere to the following guidelines:

- The activity ``doc://com.apple.foundation/documentation/Foundation/NSUserActivity/title`` should be clear and concise. This text describes the content of the link, like “Photo taken on July 27, 2020” or “Conversation with Maria”. Use nouns for activity titles.
- Keep the app’s current activity up to date, using ``doc://com.apple.foundation/documentation/Foundation/NSUserActivity/becomeCurrent()`` and ``doc://com.apple.foundation/documentation/Foundation/NSUserActivity/resignCurrent()``.
- Linkable identifiers (listed above) must be stable and consistent for the same content. When you link from a note to a document in an app, and later revisit that document, the system shows an indicator linking back to the note. The system compares identifiers to check that the document is the same as the original source of the link.
- Maintain support for activities provided by your app, and support navigating to linked content indefinitely. Links added to notes are important to people, who may feel that a broken link indicates data loss.
- Gracefully handle attempts to navigate to an activity that points to content that doesn’t exist. For example, you can redirect to the new location of moved content, or show an error message. This situation may happen with shared notes, when a person links to content that exists only on another person’s device.

### Search results

If your [`NSUserActivity`](/documentation/Foundation/NSUserActivity) objects contain information that a person might want to search for later, set the [`isEligibleForSearch`](/documentation/Foundation/NSUserActivity/isEligibleForSearch) property to <doc://com.apple.documentation/documentation/Swift/true>. When you enable search, Spotlight indexes your user activity objects and considers them during subsequent on-device searches. For example, if a person viewed information about a particular restaurant in your app, you’d enable search for the corresponding user activity object. Subsequent searches for restaurants using Spotlight could then include the results obtained from your user activity object.

In addition to on-device searches, you can contribute URLs accessed by your app with the global Spotlight search engine. Sharing a URL helps Spotlight improve its own search results for other people. To contribute a URL, put the URL in the [`webpageURL`](/documentation/Foundation/NSUserActivity/webpageURL) property of your activity object and set the [`isEligibleForPublicIndexing`](/documentation/Foundation/NSUserActivity/isEligibleForPublicIndexing) property to <doc://com.apple.documentation/documentation/Swift/true>.

> Important:
> Your app must maintain a strong reference to any activity objects that you use for search results.

Employ user activity objects to record user-initiated activities, not as a general-purpose indexing mechanism of your app’s data. To index all of your app’s content, and not just the content touched by people, use the APIs of the <doc://com.apple.documentation/documentation/CoreSpotlight> framework.

## Topics

### Creating a user activity object

[Creating a user activity object](/documentation/Foundation/creating-a-user-activity-object)

Identify key user interactions and include the information to restore them later.

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

Creates a user activity object with the specified type.

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

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

### Accessing activity information

[`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.

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

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

[`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.

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

A string that identifies the user activity’s content.

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

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

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

A set of properties that describe the activity.

[`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 value used to identify the user activity.

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

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

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

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

### Specifying the activity’s eligibility

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

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

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

A Boolean value that indicates whether the activity should be added to the on-device index.

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

A Boolean value that indicates whether the activity can be publicly accessed by all iOS users.

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

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

### Registering and invalidating user 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.

### Deleting saved user activities

[`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.

### Accessing the delegate

[`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.

### 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.

### Continuing web browsing

[`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.

### Donating to Siri Shortcuts

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

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

[`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.

### Continuing Siri interactions

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

The SiriKit interaction object to use when configuring your app.

### Retrieving NFC tag data

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

The NDEF message read by the system in the background.

### Processing barcodes

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

The barcode that the system scanner passes in.

### Sharing map item information

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

Attaches the specified map item to a user activity object.

### Working with media

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

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

### 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 ClassKit

[`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.

### Identifying activity types

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

An activity that continues from Handoff or a universal link.

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

### 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.

### Instance Properties

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

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

[`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.



---

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)
