获取热门搜索
如需获取热门搜索,请对 ContextualSearchRuntime 调用 getTrendingSearches 方法。此方法接受单个
GetTrendingSearchesOptions
,您可以在其中指定返回的热门搜索数量上限。
返回的 SearchSuggestions 对象不包含任何可访问的属性。它包含呈现热门搜索所需的所有信息,但除此之外是不透明的。
Swift 使用 Swift 并发样式,Objective-C 使用回调函数。
Swift
getTrendingSearches(withOptions:)
Task {
let suggestions = try await searchRuntime.getTrendingSearches(
withOptions: GetTrendingSearchesOptions())
}
Objective-C
getTrendingSearchesWithOptions
[searchRuntime
getTrendingSearchesWithOptions:
[[GetTrendingSearchesOptions alloc] init]
completionHandler:^(SearchSuggestions *_Nullable suggestions,
NSError *_Nullable error) {
// error will be not null if there is an error.
// On success, suggestions will be non null.
}];