本页介绍了如何设置 iOS SDK。如果您尚未 完成前提条件,请先完成 这些条件。
依赖项
Swift Package Manager
在 Xcode 中,依次转到“File”(文件)>“Add Packages…”(添加软件包…),安装 Google-SearchInApps-SDK Swift 软件包。
在显示的提示中,搜索 Google-SearchInApps-SDK Swift 软件包的 GitHub 代码库:
https://github.com/google/search-in-apps.git
- 选择您要使用的 Google-SearchInApps-SDK Swift 软件包版本。对于新项目,我们建议使用 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键,其值为字符串形式的应用客户端标识符(见上文)。
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];