Class

NSUserActivity

A representation of the state of your app at a moment in time. 現時点でのあなたのアプリの状態の表現。

Declaration 宣言

class NSUserActivity : NSObject

Overview 概要

An NSUserActivity object provides a lightweight way to capture the state of your app and put it to use later. NSUserActivityオブジェクトは、あなたのアプリの状態をキャプチャ(捕獲、記録)して、それを後で使うようにする軽量な方法を提供します。 Create this object to capture information about what the user 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 the user. To allow users to continue an activity on another device, see 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 INInteraction object to its 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. SiriKitがあなたのアプリを何らかの理由のために起動する必要があるならば、それはユーザアクティビティオブジェクトを作成して、適切なINInteractionオブジェクトをそれのinteractionプロパティへと代入します。あなたのアプリは、その相互作用情報を使って自身を構成設定します、そしてSiriKitによって開始された相互作用に関連して情報を表示します。あなたはまたSiriKitに、あなたがあなたのアプリに渡されることを望む追加データを含んでいる、あつらえのユーザアクティビティオブジェクトを提供できます。

In iOS 15 and later, the user can share content they’re viewing by asking Siri to “share this”. Apps built with Mac Catalyst provide the same capability with an NSSharingServicePickerToolbarItem in the toolbar. You can use activityItemsConfiguration or activityItemsConfigurationSource to provide shareable content. In iOS, if both of those properties are nil, Siri uses the 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. To appear as a link, the content must be the app’s current activity, and provide at least one of the following identifiers:

webpageURL

An https: URL, ideally in a canonical form that’s consistent every time the user visits the same content.

persistentIdentifier

A string that uniquely identifies the content in this domain. The identifier should identify the same content across devices.

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 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 becomeCurrent() and 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 the user, 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 user links to content that exists only on another user’s device.

Search Results

If your NSUserActivity objects contain information that the user might want to search for later, set the isEligibleForSearch property to true. When you enable search, Spotlight indexes your user activity objects and considers them during subsequent on-device searches. For example, if the user viewed information about a particular restaurant in your app, you would 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. あなたのNSUserActivityオブジェクトが、ユーザが後で検索したいかもしれない情報を含むならば、isEligibleForSearchプロパティをtrueに設定してください。あなたが検索を可能にする場合、Spotlightはあなたのユーザアクティビティオブジェクトの索引作成をして、それらを以降のデバイス上の検索の間を通して考慮に入れます。例えば、ユーザがある特定のレストランについての情報をあなたのアプリにおいて閲覧したならば、あなたはその対応するユーザアクティビティオブジェクトに対して検索を可能にするでしょう。Spotlightを使ってのレストランについての以降の検索は、あなたのユーザアクティビティオブジェクトから入手された結果をそのとき含むことができます。

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 users. To contribute a URL, put the URL in the webpageURL property of your activity object and set the isEligibleForPublicIndexing property to true. デバイス上の検索に加えて、あなたは、あなたのアプリによってグローバルSpotlight検索エンジンをつかってアクセスされたURLを提供できます。URLの共有は、他のユーザに対してSpotlightが自身の検索結果を向上させる助けとなります。URLを提供するには、そのURLをあなたのアクティビティオブジェクトのwebpageURLプロパティの中に入れてください、そしてisEligibleForPublicIndexingプロパティをtrueに設定してください。

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 the user, use the APIs of the Core Spotlight framework.

Topics 話題

Creating a User Activity Object ユーザアクティビティオブジェクトを作成する

Accessing Activity Information アクティビティ情報にアクセスする

Specifying the Activity’s Eligibility 指定されたアクティビティのもつ適格性

Registering and Invalidating User Activities ユーザアクティビティの登録と無効化

Deleting Saved User Activities 保存されたユーザアクティビティを削除する

Accessing the Delegate 委任先にアクセスする

Working with Continuation Streams 継続ストリームを扱う

Continuing Web Browsing ウェブブラウズを継続する

Donating to Siri Shortcuts Siriショートカットに提供する

Continuing Siri Interactions Siri相互作用を継続する

Retrieving NFC Tag Data NFCタグデータを回収する

Processing Barcodes バーコードを処理する

Sharing Map Item Information マップ項目情報を共有する

Working with Media メディアを扱う

Managing Type-Safe Access to User Info ユーザ情報への型安全なアクセスを管理する

Working with ClassKit ClassKitを扱う

Identifying Activity Types

Reporting Errors

Relationships 関係

Inherits From 継承元

Conforms To 次に準拠

See Also 参照

Activity Sharing アクティビティを共有する