熱門搜尋

取得熱門趨勢

如要取得熱門搜尋,請呼叫 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.
                            }];

多媒體

如要顯示熱門搜尋方塊,請使用與搜尋建議相同的方式

下一步:顯示搜尋結果