수색…


소개

NSUserActivity 객체를 사용하여 앱의 중요한 이벤트를 시스템과 조정할 수 있습니다. iOS와 macOS를 실행하는 여러 장치 간의 핸드 오프 의 기초입니다. 또한 공개 색인 생성 및 기능 보강을 향상 시키거나 앱의 스포트라이트 검색 결과를 생성하는데도 사용할 수 있습니다. iOS 10부터는 SiriKit을 사용하여 앱과 Siri 간의 상호 작용을 조정하는데도 사용할 수 있습니다.

비고

활동 유형

지원되는 활동 유형은 앱의 Info.plist 파일에서 NSUserActivityTypes 키 아래에 정의되어야합니다. 활동은 개발자 팀 ID와 관련이 있습니다. 즉 팀 ID가 동일한 앱 간에는 활동 조정이 제한됩니다 (예 : 'Safari'는 'Chrome'의 핸드 오프 활동을 수락 할 수 없거나 그 반대의 경우도 있음).

현재 활동되기 / 끝내기

becomeCurrent 를 사용하여 현재 활동을 표시하면 핸드 오프 또는 스포트라이트 인덱싱에 사용할 수 있습니다. 한 번에 하나의 활동 만 현재 상태 일 수 있습니다. resignCurrent 를 호출하여 무효화하지 않고 활동을 비활성으로 표시 할 수 있습니다.

활동을 + invalidate 하면 동일한 인스턴스가 다시 현재 상태가되지 않을 수도 있습니다.

SiriKit을 제공 할 때 현재 활동으로 표시하지 마십시오.

검색 색인 생성

액티비티는 앱 내에서 범용 인덱싱 메커니즘으로 사용되어서는 안됩니다 . 대신 사용자가 시작한 작업에 응답하여 사용해야합니다. 앱의 모든 콘텐츠를 색인 생성하려면 CoreSpotlight를 사용하십시오.

NSUserActivity 만들기

NSUserActivity 객체를 만들려면 Info.plist 파일에서 지원하는 활동 유형을 선언해야합니다. 지원되는 활동은 응용 프로그램에 의해 정의되며 고유해야합니다. 액티비티는 역 도메인 스타일 명명 체계 (예 : "com.companyName.productName.activityName")를 사용하여 정의됩니다. Info.plist의 엔트리는 다음과 같습니다.

NSUserActivityTypes [정렬]
- item0 com.companyName.productName.activityName01
- item1 com.companyName.productName.activityName02

지원되는 모든 활동 유형을 정의한 후에는 애플리케이션 코드에 액세스하여 사용할 수 있습니다.

NSUserActivity 객체를 만들려면 다음을 수행해야합니다.

// 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];

이 후, 위의 활동은 핸드 오프에 사용할 수 있어야합니다 ( "핸드 오프"를 적절히 처리하기 위해 더 많은 작업이 필요함).



Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow