קבלת תוצאות פופולריות
כדי לקבל את החיפושים הפופולריים, מבצעים קריאה ל-method getTrendingSearches ב-ContextualSearchRuntime. השיטה הזו מקבלת GetTrendingSearchesOptions יחיד, שבו אפשר לציין את המספר המקסימלי של הנושאים הפופולריים שיוחזרו.
אובייקט SearchSuggestions שמוחזר לא מכיל מאפיינים נגישים. הוא מכיל את כל המידע שנדרש כדי להציג את הנושאים הפופולריים בחיפוש, אבל הוא לא שקוף.
ב-Swift נעשה שימוש בסגנון Swift Concurrency, וב-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.
}];
רשת המדיה
כדי להציג צ'יפים של חיפושים פופולריים, משתמשים באותה שיטה כמו בהצעות לחיפוש.