開始使用
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁說明如何設定 iOS SDK。如果您尚未完成前置作業,請先完成這些作業。
依附元件
Swift Package Manager
在 Xcode 中,依序點選「File」>「Add Packages...」(新增 Package),安裝 Google-SearchInApps-SDK Swift Package。
在隨即顯示的提示中,搜尋 Google-SearchInApps-SDK Swift 套件 GitHub 存放區:
https://github.com/google/search-in-apps.git
- 選取要使用的 Google-SearchInApps-SDK Swift 套件版本。對於新專案,建議您使用「升級至下一個主要版本」
完成後,Xcode 就會開始解析套件依附元件,並在背景下載這些依附元件。如要進一步瞭解如何新增套件依附元件,請參閱 Apple 的文章。
CocoaPods
使用 CocoaPods 將 Google-SearchInApps-SDK 匯入 iOS 專案。開啟專案的 Podfile,並將這一行新增至應用程式目標:
pod 'Google-SearchInApps-SDK'
然後在指令列中執行:
pod install --repo-update
如果您是第一次使用 CocoaPods,請參閱其官方說明文件,瞭解如何建立及使用 Podfiles。
更新 Info.plist
更新應用程式的 Info.plist
檔案,新增兩個鍵:
GSAAPIKey
鍵,其中包含 SDK API 金鑰的字串值 (請參閱上方說明)。
GSAClientIdentifier
鍵,其中包含應用程式用戶端 ID 的字串值 (請參閱上方說明)。
Info.plist
範例
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>GSAAPIKey</key>
<string>ABC123...xyz890</string>
<key>GSAClientIdentifier</key>
<string>ms-demo-app-sia</string>
...
</dict>
</plist>
Init
建立 ContextualSearchRuntime
的執行個體
Objective-C
ContextualSearchRuntime
ContextualSearchRuntime *searchRuntime = [[ContextualSearchRuntime alloc] init];
下一步:搜尋功能arrow_forward
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-11-08 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-11-08 (世界標準時間)。"],[[["This guide explains how to integrate the iOS SDK for Google Search in Apps, covering setup, dependency management, and initialization."],["Before starting, ensure you have fulfilled the prerequisites mentioned in the linked documentation."],["You can add the SDK to your project using either Swift Package Manager or CocoaPods, with instructions provided for both methods."],["Remember to update your app's `Info.plist` file with your API key and client identifier for the SDK to function correctly."],["Finally, initialize the `ContextualSearchRuntime` to begin utilizing the search functionalities."]]],["To set up the iOS SDK, first install the Google-SearchInApps-SDK via Swift Package Manager or CocoaPods. For Swift Package Manager, add the package via Xcode using the provided GitHub repository URL. For CocoaPods, add `pod 'Google-SearchInApps-SDK'` to your Podfile and run `pod install --repo-update`. Then, update your app's `Info.plist` by adding `GSAAPIKey` and `GSAClientIdentifier`. Finally, initialize a `ContextualSearchRuntime` instance in either Swift or Objective-C.\n"]]