Ricerche di tendenza

Ricevere le tendenze

Per visualizzare le ricerche di tendenza, chiama il metodo getTrendingSearches su ContextualSearchRuntime. Questo metodo accetta un singolo GetTrendingSearchesOptions in cui puoi specificare il numero massimo di tendenze restituite.

L'oggetto SearchSuggestions restituito non contiene proprietà accessibili. Contiene tutte le informazioni necessarie per visualizzare le ricerche di tendenza, ma per il resto è opaco.

Swift utilizza lo stile di concorrenza di Swift, mentre Objective-C utilizza una funzione di callback.

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.
                            }];

Display

Per visualizzare i chip di ricerca di tendenza, utilizza lo stesso metodo utilizzato per i suggerimenti di ricerca.

Passaggio successivo: visualizzare i risultati di ricerca