使用 CocoaPods 设置 InboxKit
自 iOS SDK 7.0.40 起可用。
InboxKit 作为 PushwooshXCFramework pod 的一个可选子规范 (subspec) 提供。您需要先集成主 SDK;如果您是从头开始,请先遵循 基本集成指南。
添加 InboxKit pod
Anchor link to- 打开您的
Podfile并将 InboxKit subspec 添加到您的应用 target 中:
target 'MyApp' do use_frameworks!
pod 'PushwooshXCFramework' pod 'PushwooshXCFramework/PushwooshInboxKit'end- 从您的项目目录运行
pod install:
pod install- 打开生成的
.xcworkspace文件。现在 InboxKit 已与主 SDK 一起链接。
显示收件箱
Anchor link to将收件箱控制器添加到任何导航流中。默认配置足以让您获得一个包含三种标准单元格类型的工作收件箱:
import PushwooshInboxKit
let inboxVC = PushwooshInboxKitViewController()navigationController?.pushViewController(inboxVC, animated: true)@import PushwooshInboxKit;
PushwooshInboxKitViewController *inboxVC = [PushwooshInboxKitViewController new];[self.navigationController pushViewController:inboxVC animated:YES];自定义收件箱
Anchor link to在 Swift 中,通过 PushwooshInboxKitAttributes 值类型配置控制器。在 Objective-C 中,使用控制器上对 @objc 友好的设置器 — PushwooshInboxKitAttributes 是一个 Swift 结构体 (struct),并且没有桥接。
var attributes = PushwooshInboxKitAttributes()attributes.pullToRefreshEnabled = trueattributes.swipeToDeleteEnabled = trueattributes.pinningEnabled = trueattributes.style.unreadBadgeColor = .systemBlueattributes.style.titleFont = .systemFont(ofSize: 17, weight: .semibold)
let inboxVC = PushwooshInboxKitViewController(attributes: attributes)PushwooshInboxKitViewController *inboxVC = [PushwooshInboxKitViewController new];[inboxVC setBackgroundColor:[UIColor systemBackgroundColor]];[inboxVC setEmptyMessage:@"You have no messages yet"];Style 结构体 (struct) 公开了默认单元格使用的所有颜色、字体、圆角半径和日期格式化器。默认情况下,每个值都是 Apple 的语义颜色,因此收件箱会自动响应系统的暗黑模式 (dark mode)。

带有通过 PushwooshInboxKitAttributes.Style 应用的自定义主题的带标题单元格。
处理点击和刷新
Anchor link to遵循 PushwooshInboxKitDelegate 以响应用户操作和刷新事件。每个方法都有一个默认实现,因此您只需覆盖所需的方法:
final class InboxCoordinator: NSObject, PushwooshInboxKitDelegate { func inboxKit(_ vc: PushwooshInboxKitViewController, didSelect message: PWInboxMessageProtocol) -> Bool { // 返回 true 以让 SDK 打开消息 URL 或富媒体。 // 如果您完全处理了点击(例如,路由到自定义屏幕),则返回 false。 return true }
func inboxKit(_ vc: PushwooshInboxKitViewController, didRefreshWith messages: [PWInboxMessageProtocol], error: Error?) { // 如果需要,在此处显示您自己的空/错误状态。 }}
inboxVC.delegate = inboxCoordinatorSDK 将批量操作作为控制器上的 @objc 方法提供,因此您可以将它们直接连接到 UIBarButtonItem:
let markAll = UIBarButtonItem( image: UIImage(systemName: "checkmark.circle"), style: .plain, target: inboxVC, action: #selector(PushwooshInboxKitViewController.markAllAsRead))let clearRead = UIBarButtonItem( image: UIImage(systemName: "trash"), style: .plain, target: inboxVC, action: #selector(PushwooshInboxKitViewController.clearReadMessages))inboxVC.navigationItem.rightBarButtonItems = [clearRead, markAll]后续步骤
Anchor link to PushwooshInboxKit API 参考 为每个公共类型生成的 DocC 文档。