Wyszukiwania zyskujące popularność

Pobieranie trendów

Aby pobrać wyszukiwania zyskujące popularność, wywołaj metodę getTrendingSearches w ContextualSearchRuntime. Ta metoda przyjmuje pojedynczy GetTrendingSearchesOptions , w którym możesz określić maksymalną liczbę zwracanych trendów.

Zwrócony obiekt SearchSuggestions nie zawiera żadnych dostępnych właściwości. Zawiera wszystkie informacje potrzebne do renderowania wyszukiwań zyskujących popularność, ale poza tym jest nieprzezroczysty.

Swift używa stylu Swift Concurrency, a Objective-C – funkcji wywołania zwrotnego.

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

Wyświetlacz

Aby wyświetlić chipy wyszukiwań zyskujących popularność, użyj tej samej metody co w przypadku sugestii wyszukiwania.

Dalej: wyświetlanie wyników wyszukiwania