Playbook IOS SDK
安装
CocoaPods
目前 PlaybookSDK 的版本为 v1.4
pod "PlaybookSDK", :git => 'https://github.com/getplaybook/Playbook-iOS-SDK.git', :tag => '1.4'
初始化 PlaybookSDK
使用您的设置信息初始化 Playbook SDK,并从任何 UIController 打开 Playbook 模态窗体。在这里,您需要三个关键信息 — 您的 SDK Token、一个 用户 ID(由您提供)以及用户所属的 用户组。
在您的 UIApplicationDelegate
类中,您可以按照以下代码块设置 Playbook SDK
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
/**
Playbook Config
*/
PlaybookSDK.set(
token: "...", // Your SDK token from app.getplaybook.io -> Settings -> App Settings
userID: "...", // A unique user id of your user
userGroups: ["..."], // An array of user group ids from app.getplaybook.io -> User Groups -> External ID, External ID = 1 is for the Everyone User group
companyName: "Acme Academy" // Your Company Name
)
/* This method is optional */
PlaybookSDK.extraSettings(PBExraSettingsData(
spinnerColor: UIColor(red: 1.00, green: 0.85, blue: 0.10, alpha: 1.00),
mainColor: UIColor(red: 1.00, green: 0.85, blue: 0.10, alpha: 1.00),
mainTitle: [
"en": "Acme Academy",
"tr": "Acme Akademi"
],
mainDescriptionText: [
"en": "Supercharge your skills with these short guides in various categories.",
"tr": "Çeşitli konu ve kategorilerdeki kısa rehberler ile kendini geliştir."
]
QRModule: true,
updateModule: true
))
...
}
加载中查询型设置
属性 | 描述 | 类型 | 默认值 |
---|---|---|---|
spinnerColor |
主要加载圈的颜色 | UIColor |
UIColor.gray |
fontFamily |
主要字体名称 | String |
为null |
mainColor |
应用主要颜色 | UIColor |
UIColor.gray |
mainTitle |
主屏幕标题 | 字典 |
为null |
mainDescriptionText |
主屏幕描述 | 字典 |
为null |
categoryDescriptionText |
主屏幕描述 | 字典 |
为null |
QRModule |
QR模块状态 | Bool |
true |
updatesModule |
更新模块状态 | Bool |
true |
本地化您的SDK
首先,您应该为SDK设置以下所示的可用语言。
PlaybookSDK.set(availableLocales: [
Locale(identifier: "EN"),
Locale(identifier: "DE"),
Locale(identifier: "TR")
])
当前版本的SDK只支持英语、土耳其语和阿拉伯语本地化。但开发者可以基于当前的JSON模板创建他们自己的本地化文件。示例模板可以在仓库的main目录下找到。
请按照以下三个基本步骤将SDK本地化为新语言:
- 设置可用语言。
- 将示例json文件复制到您的bundle中。该文件必须位于一个命名为localization的
项目相对目录
。 - 用语言简写标识符替换文件名。例如,
de.json
。
展示学院、更新或两者
在Playbook中,您可以选择在不同位置分别显示主要模块(学院和更新),或者一起显示。在任何`UIViewController`实例中,您可以使用以下列出的方法。
// Presenting both academy and updates module
PlaybookSDK.presentListViewFrom(self, animated: true)
// Presenting only update module
PlaybookSDK.presentUpdatesListViewFrom(self, animated: true)
// Presenting only academy module
PlaybookSDK.presentAcademyListViewFrom(self, animated: true)
更新推送通知
用于Playbook SDK推送通知的应用应该在其数据载荷部分有`pb_update_id`。
"data": {
"pb_update_id": "PU69a1" // Update ID from app.getplaybook.io -> Updates -> Campaign ID
}
在您的`UIApplicationDelegate`类中,您可以使用以下代码块设置playbook SDK UpdateModule
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
...
PlaybookSDK.catchTheNotification(notification.request.content.userInfo)
completionHandler([.alert, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
...
PlaybookSDK.catchTheNotification(response.notification.request.content.userInfo, andOpen: true)
completionHandler()
}