SearchApi
모듈은 iOS 검색 API인 Core Spotlight와 상호 작용하기 위한 일반적인 React Native 인터페이스를 제공합니다.
iOS 검색 API에 대한 자세한 내용은 https://developer.apple.com/ios/search/를 참조하세요.
npm install react-native-search-api --save
react-native link
AppDelegate.m
상단에 다음 줄을 추가하세요.
# import " RCTSearchApiManager.h "
AppDelegate 구현에서 다음을 추가합니다.
- ( BOOL )application:(UIApplication *)application continueUserActivity:( NSUserActivity *)userActivity restorationHandler:( void (^)( NSArray * _Nullable))restorationHandler {
return [RCTSearchApiManager application: application continueUserActivity: userActivity restorationHandler: restorationHandler];
}
다음과 같이 구성 요소에서 검색 항목 열기 이벤트를 구독합니다.
componentDidMount ( ) {
< ... >
SearchApi . addOnSpotlightItemOpenEventListener ( this . handleOnSpotlightItemOpenEventListener ) ;
SearchApi . addOnAppHistoryItemOpenEventListener ( this . handleOnAppHistoryItemOpenEventListener ) ;
}
메모리 누수를 방지하려면 구독을 취소하는 것을 잊지 마세요.
componentWillUnmount ( ) {
< ... >
SearchApi . removeOnSpotlightItemOpenEventListener ( this . handleOnSpotlightItemOpenEventListener ) ;
SearchApi . removeOnAppHistoryItemOpenEventListener ( this . handleOnAppHistoryItemOpenEventListener )
}
일반적으로 검색을 사용하여 앱이 시작되었는지 여부에 관심이 있어야 하므로 다음 두 가지 방법을 사용하는 것이 좋습니다.
// For the spotlight item:
SearchApi . getInitialSpotlightItem ( ) . then ( result => {
if ( result ) {
console . log ( 'Started with a spotlight item!' )
}
} )
// For the app history item:
SearchApi . getInitialAppHistoryItem ( ) . then ( result => {
if ( result ) {
console . log ( 'Started with an app history item!' )
}
} )
새 스포트라이트 항목을 생성하려면 indexSpotlightItem
또는 indexSpotlightItems
사용하세요.
SearchApi . indexSpotlightItem ( item ) . then ( result => {
console . log ( 'Success' ) ;
} ) . catch ( err => {
console . log ( 'Error: ' + err ) ;
} ) ;
앱 기록에 새 항목을 추가하려면 createUserActivity
사용하세요.
SearchApi . indexAppHistoryItem ( item ) . then ( result => {
console . log ( 'Success' ) ;
that . setState ( { labelText : 'Success' } ) ;
} ) . catch ( err => {
console . log ( 'Error: ' + err ) ;
that . setState ( { labelText : ( 'Error: ' + err ) } ) ;
} ) ;
항목이 지정할 수 있는 매개변수는 다음과 같습니다.
스포트라이트 및 앱 기록 항목을 생성하기 위해 전달된 사전에는 공통 키와 특정 키가 있습니다. 가능한 모든 키 목록은 다음과 같습니다.
title
: 문자열항목의 제목입니다. 두 항목 유형 모두에 필요합니다.
contentDescription
: 문자열항목에 대한 설명입니다. 선택 과목.
keywords
: 배열검색 항목에 할당된 키워드 배열입니다. 선택 과목.
thumbnail
: string|int|객체 검색결과에 표시될 썸네일입니다. Image
구성 요소의 source
와 동일한 형식입니다. 선택 과목.
예:
var localItem = {
< ... > ,
thumbnail : require ( '/react-native/img/favicon.png' )
} ;
var remoteItem = {
< ... > ,
thumbnail : { uri : 'https://facebook.github.io/react-native/docs/assets/favicon.png' }
} ;
자세한 내용은 설명서를 참조하세요.
uniqueIdentifier
: 문자열나중에 항목 열기 이벤트 중에 전달되는 스포트라이트 항목의 고유 식별자입니다. 필수의.
domain
: 문자열스포트라이트 항목의 도메인입니다. 선택 과목.
userInfo
: 객체나중에 아이템 개봉 이벤트 때 전달되는 사전입니다. 필수의.
eligibleForPublicIndexing
: 부울 true
로 설정하면 공개 색인에 항목을 추가할 수 있는 플래그입니다. 선택 과목.
expirationDate
: 날짜사용자 활동 항목의 만료 날짜입니다. 선택 과목.
webpageURL
: 문자열앱 웹사이트의 동일한 콘텐츠를 나타내는 페이지의 URL입니다.
© 2017 PresenceKit by Ombori AB