本頁說明如何設定 iOS SDK。如果尚未完成前置作業,請先完成。
依附元件
Swift Package Manager
在 Xcode 中,依序前往「File」(檔案) >「Add Packages...」(新增套件...),然後安裝 Google-SearchInApps-SDK Swift Package。
使用隨即出現的提示詞框,搜尋「Google-SearchInApps-SDK Swift Package GitHub repository」:
https://github.com/google/search-in-apps.git
- 選取要使用的 Google-SearchInApps-SDK Swift Package 版本。如果是新專案,建議選用「Up to Next Major Version」(升級至下一個主要版本)
完成後,Xcode 會開始解析並在背景下載套件依附元件。如要進一步瞭解如何新增套件依附元件,請參閱 Apple 的文章。
CocoaPods
使用 CocoaPods 將 Google-SearchInApps-SDK 匯入 iOS 專案。開啟專案的 Podfile,將下列程式碼加進應用程式的目標:
pod 'Google-SearchInApps-SDK'
然後從指令列執行:
pod install --repo-update
如果您是 CocoaPods 新手,請參閱官方文件,瞭解如何建立及使用 Podfile。
更新 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 的執行個體
Swift
let contextualSearchRuntime = ContextualSearchRuntime()
Objective-C
ContextualSearchRuntime *searchRuntime = [[ContextualSearchRuntime alloc] init];