SDK iOS
- [ x ] 初始化
- [ x ] 识别
- [ x ] SHA1 转换
- [ x ] 跟踪
- [ x ] 通知
- [ x ] Deeplink 处理
- [ x ] 离线管理
- iOS 11.0+
- Xcode 11.3.1+
要使用 Cocoapods 在您的项目中安装最新版本的 Dito SDK,请将 pod 添加到您的 podfile 中
pod 'DitoSDK'
要安装特定版本,包括版本号
pod 'DitoSDK', '~> 1.0.0'
在某些情况下,可能需要使用特定的分支来进行一些调整或修复。在这种情况下,只需指定分支即可
pod 'DitoSDK', :git => 'https://github.com/ditointernet/dito_ios.git', :branch => 'NOME_DA_BRANCH'
ps.: 要将 cocoapods 包含到项目中,[请参考教程] (https://guides.cocoapods.org.cn/using/using-cocoapods.html)
在 podfile 中添加后,执行命令 pod install --repo-update 以安装和使用 pod。
要手动安装 Dito SDK 到您的项目中(不使用 cocoapods),您需要将 DitoSDK.framework 文件拖放到项目所在的 Framework 文件夹中。
在这个仓库的 Example 文件夹中有 SDK 的使用和配置示例。
您需要在您的项目 .plist
文件中设置 Dito dashboard 的 App Key
和 App secret
,使用与以下示例中相同的确切键
您需要在您的项目 AppDelegate.swift
文件中进行 SDK 的初始化。
import DitoSDK
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
Dito.shared.configure()
...
}
let customData = ["x": "y"]
let ditoUser = DitoUser(name: "My name",
gender: .masculino,
email: "[email protected]",
birthday: Date(),
location: "My city",
createdAt: Date(),
customData: customData)
Dito.identify(id: "My user id", data: ditoUser)
let sha1String = Dito.sha1(for: "String to convert")
let event = DitoEvent(action: "my-current-event-to-track")
Dito.track(event: event)
为了捕获和处理通知,您需要在项目中包含一个初始化函数,该函数负责捕获原生通知。该函数可以在示例项目中找到,并执行关于接收到的推送的通知的读取和内部流程。应将其包含在项目的原生 'AppDelegate' 类中
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
//Ver sessão 'tratamento de deeplink' para definição interna desta função
}
项目提供了在读取通知时接收通知 Deeplink 的选项。为此,只需在 notificationRead 调用中包含闭包的发送即可。
Dito.notificationRead(with: userInfo, callback: { deeplink in
print(deeplink) })
在示例中,变量 "deeplink" 返回 Deeplink 的值,并在块中执行 print 动作。包含是可选的,如果没有捕捉 Deeplink 的需求可以省略
Dito.notificationRead(with: userInfo)
完整来说,有两组添加到 AppDelegate 中的函数选项。
包含 Deeplink 捕获
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Dito.notificationRead(with: userInfo, callback: { deeplink in print(deeplink) })
}
不包含 Deeplink 捕获
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Dito.notificationRead(with: userInfo)
}
Dito.registerDevice(token: "My notification token", tokenType: .apple)
Dito.unregisterDevice(token: "My notification token", tokenType: .apple)
方法接收一个 dictionary
作为参数,该参数在推送时发送。不必要像以下示例那样在委托方法中实现
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Dito.notificationRead(with: userInfo)
}
如以下示例所示,也可以获取 deepLink
进行流程定向
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let notificationRead = Dito.notificationRead(with: userInfo)
print(notificationRead.deepLink)
}
要激活日志记录,需要在项目 scheme 中的 Arguments Passed On Launch
将标志 EnabledDebug
设置为启用。
ioasys, [email protected]
DitoSDK 在 MIT 许可证下可用。有关更多信息,请参见 LICENSE 文件。