目前一個用戶端 ID 只能支援一項搜尋結果功能。如要在應用程式中使用多項搜尋功能,請使用多個用戶端 ID。此外,如要在應用程式的不同進入點使用相同的搜尋功能,也應為每個進入點使用不同的用戶端 ID,以區分流量。
針對每項要求,您可以在 GetSearchSuggestionsOptions、GetTrendingSearchesOptions 或 GetSearchContentOptions 中主動設定用戶端 ID,這個 ID 會覆寫 Info.plist 檔案中的預設用戶端 ID (僅適用於這項要求)。
Swift
getSearchSuggestions(withOptions:)
Task {
let options = GetSearchSuggestionsOptions(withTextContext:['Sample Query', 'Another query string'])
options.clientId = "client id"
let suggestions = try await searchRuntime.getSearchSuggestions(
withOptions: options)
}
Objective-C
getSearchSuggestionsWithOptions
GetSearchSuggestionsOptions *options = [[GetSearchSuggestionsOptions alloc] initWithTextContext: @[@'Sample Query', @'Another query string' ]];
options.clientId = [NSString stringWithFormat:@"client id"];
[searchRuntime
getSearchSuggestionsWithOptions:options
completionHandler:^(SearchSuggestions *_Nullable suggestions,
NSError *_Nullable error) {
// error will be not null if there is an error.
// On success, suggestions will be non null.
}];