開始使用

本頁說明如何設定 iOS SDK。如果您尚未完成前置作業,請先完成這些作業。

依附元件

Swift Package Manager

  1. 在 Xcode 中,依序點選「File」>「Add Packages...」(新增 Package),安裝 Google-SearchInApps-SDK Swift Package。

  2. 在隨即顯示的提示中,搜尋 Google-SearchInApps-SDK Swift 套件 GitHub 存放區:

https://github.com/google/search-in-apps.git
  1. 選取要使用的 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 檔案,新增兩個鍵:

  1. GSAAPIKey 鍵,其中包含 SDK API 金鑰的字串值 (請參閱上方說明)。
  2. 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

ContextualSearchRuntime

let contextualSearchRuntime = ContextualSearchRuntime()

Objective-C

ContextualSearchRuntime

ContextualSearchRuntime *searchRuntime = [[ContextualSearchRuntime alloc] init];

下一步:搜尋功能