本页介绍了如何设置 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];