DASHEmbed 2.0.0

DASHEmbed 2.0.0

Ryan Gant 维护。



DASHEmbed 2.0.0

  • DASH

DASH

目的

此库提供了一种简单的方法,将 DASH 移动体验嵌入 iOS 应用程序中。有关更多信息,请访问 DASH

安装

使用 DASHEmbed 最简单的方法:CocoaPods

pod 'DASHEmbed'

手动安装:静态框架

  • 下载包含预构建的 2.0.0 框架资源的 zip 文件 在此。 此框架是用 iOS 12.0 的基本 SDK 在 Xcode 11.2.1 中构建的,使用 Objective-C,并启用了 Bitcode。需要 iOS 10+。如果您需要更多自定义(不同的 Xcode 版本,禁用 Bitcode),您可以按照以下步骤自行构建框架。其他下载可以在 发布 页面上找到。
或者
  • 使用“DASHEmbed-Aggregate”目标构建静态框架。(构建到仓库根目录)
  • 使用“DASHResources”目标构建资源包。(构建到产品)
然后
  • 将DASHEmbed.framework和DASHEmbed.resources复制到您的项目中(但不要将其添加到任何目标中)。
  • 将DASHEmbed.framework添加到您希望与DASHEmbed一起使用的目标“嵌入的二进制文件”列表中。这应该会自动将其添加到“链接的框架和库”列表中。
  • 将DASHEmbed.resources添加到您希望与DASHEmbed一起使用的目标。
  • 由于DASHEmbed是用Swift编写的,确保您包含Swift标准库(如果您还没有的话)。(当您尝试使用DASHEmbed时,如果遇到有关swift库的运行时错误,您将知道)。只需将您的目标构建设置中的“始终嵌入Swift标准库”设置为“是”即可。这将包括所需的一切。确保在更改这些项目设置时清理之间的构建,因为它们不一定在下一个完整构建之前更新。
注意
  • DASHEmbed.framework包含一个包含位代码和以下架构的切片的大二进制文件 - (x86_64 i386 armv7 armv7s arm64)。这允许框架在所有设备和模拟器上运行,但当前状态下将不被App Store接受。要删除提交中不需要的架构,请查看这篇文章。他包括一个可以添加为构建阶段的构建脚本,这将删除除了您捆绑框架中的活动架构之外的所有架构。

手动安装:源

  1. 将“DASHEmbed/Framework”下的所有内容复制到您的项目中。

使用方法

需求

(2.0.0) iOS 12+,用 Objective-C 重写以提高跨平台兼容性
(1.2.0) iOS 12+,Swift 5.0
(1.0.0 - 1.1.0) iOS 11+,Swift 4.0
用户位置用于未来基于位置的功能。

要启用,请为 NSLocationWhenInUseUsageDescription plist 键设置描述。

启用推送通知功能

我们需要从苹果开发者门户获取以下内容:1) 推送通知加密密钥 (.p8)、2) 密钥ID、3) 开发者团队ID和4) 应用程序包标识符。有关获取这些资产的详细信息,请参阅建立基于令牌的APNs连接部分中的“从苹果获取加密密钥和密钥ID”。

请注意,DASH框架和相关通知不影响徽章计数。

在收到上述推送资产后,我们将为您提供用于应用程序的App ID。

创建DASHConfig

创建DASHConfig。这是用于初始化DASH库所需的必要信息。

let appId = "APP_ID"
let dashConfig = DASHConfig(appId: appId)

第二个初始化器允许您使用DASH开发服务器进行测试。

let dashConfig: DASHConfig
#if DEBUG
dashConfig = DASHConfig(appId: appId, useDevelopmentServers: true)
#else
dashConfig = DASHConfig(appId: appId)
#endif

初始化DASH库

使用单例初始化库。

DASH.team.start(with: dashConfig)

设置推送令牌以启用出价通知

//Sets the user's push token for outbid notifications
DASH.team.setUserPushToken(with: deviceToken)

处理推送通知

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    //Check if DASH can handle the notification
    if DASH.team.canHandleNotification(response.notification) {
        DASH.team.setNotificationData(from: response.notification)
        //Trigger the display of the DASHViewController in your app
    }

    //Else, Handle other notifications

    completionHandler()
}

设置用户的电子邮件以启用电子邮件自动填充。DASH也会确定此用户是否已有DASH账户

let email = "[email protected]"
DASH.team.setUserEmail(email)

显示提供的DashViewController

guard let dashViewController = DASH.team.dashViewController() else { return }
dashViewController.delegate = self //Optionally set delegate

//Add a close button
let closeButton = UIBarButtonItem(title: "Close", style: .plain, target: self, action: #selector(closeDASHModal))
dashViewController.navigationItem.leftBarButtonItem = closeButton

以模态方式显示

//Present
let navigationController = UINavigationController(rootViewController: dashViewController)
present(navigationController, animated: true, completion: nil)

或在导航堆栈上推入

navigationController?.pushViewController(dashViewController, animated: true)

查看当前文档