รับเนื้อหาการค้นหา
เราได้เพิ่มการรองรับการรับ UI เนื้อหาการค้นหาใน SDK
Search Content
เป็นคำทั่วไปที่แสดงถึงฟีเจอร์เนื้อหาประเภทต่างๆ โปรดดูส่วนต่อไปนี้สำหรับวิธีขอฟีเจอร์เนื้อหาแต่ละประเภทตามลำดับ
Search Repeat
เรียกใช้เมธอด getSearchContent
ใน ContextualSearchRuntime
เมธอดนี้ใช้ GetSearchContentOptions
รายการเดียวที่คุณระบุข้อความที่จะใช้เพื่อรับเนื้อหาการค้นหาได้ หากต้องการดูการค้นหาซ้ำ ให้ส่งข้อความการค้นหาซ้ำไปยังอินสแตนซ์ GetSearchContentOptions
ออบเจ็กต์ SearchContents
ที่แสดงไม่มีพร็อพเพอร์ตี้ที่เข้าถึงได้
ไฟล์นี้มีข้อมูลที่จำเป็นทั้งหมดในการแสดงผลเนื้อหาการค้นหา แต่จะไม่แสดงผล
SwiftUI
Task {
let sampleSearchRepeat = "search repeat text"
let options = GetSearchContentOptions(searchRepeat: sampleSearchRepeat)
let searchContents: SearchContents =
try await contextualSearchRuntime.getSearchContent(withOptions: options)
}
Objective-C
GetSearchContentOptions *options =
[[GetSearchContentOptions alloc] initWithSearchRepeat:@"sample search repeat"];
[_contextualSearchRuntime getSearchContentWithOptions:options
completionHandler:^(SearchContents *_Nullable contents,
NSError *_Nullable error) {
// error will be not null if there is an error.
// On success, contents will be non null.
}];
แสดงเนื้อหาการค้นหา
หากต้องการแสดงเนื้อหาการค้นหา ให้ใช้วิธีการต่อไปนี้
SwiftUI
var customizationOptions = SearchContentViewOptions()
...
VStack {
ForEach(searchContents.searchContentBlocks) { block in
SearchContentView(blockData: block, options: customizationOptions)
}
}
Objective-C
for (SearchContentBlockData *block in ((SearchContents *)_searchContents)
.searchContentBlocks) {
SearchContentViewController *blockView = [[SearchContentViewController alloc]
initWithOptions:[[SearchSuggestionsViewOptions alloc] init]];
blockView.blockData = block;
[_searchContentStackView addSubview:blockView.view];
[blockView addToViewController:self];
}