TSuchi
Tsuchi 是一个出色的 Firebase Cloud Messaging 包装器。
您可以轻松且类型安全地处理 FCM。
使用
注册/注销通知
User.login {
// register remote notification (show dialog if user not determined about notification permission.)
Tsuchi.shared.register { authorized in
//...
}
}
User.logout {
Tsuchi.shared.unregister { authorized in
//...
}
}
订阅推送通知
-
- 创建有效负载模型(必须遵守
PushNotificationPayload
)
- 创建有效负载模型(必须遵守
struct FCMNotificationPayload: PushNotificationPayload {
let eventName: String?
let eventType: EventType?
var aps: APS?
}
-
- 调用
Tsuchi.subscribe(_:completion)
- 调用
Tsuchi.shared.subscribe(FCMNotificationPayload.self) { result in
switch result {
case .success(let (notification, mode)):
print(notification.name, mode)
case .failure(let error):
print(error)
}
}
订阅/取消订阅主题
public enum AppTopic: String, TopicType {
case owner
case member
}
// Subscribe topic
Tsuchi.shared.subscribe(toTopic: AppTopic.owner)
// Unsubscribe topic
Tsuchi.shared.unsubscribe(fromTopic: AppTopic.owner)
示例
要运行示例项目,请先克隆仓库,然后从“Example”目录运行pod install
。
需求
安装
Tsuchi 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中
pod 'Tsuchi'
作者
miup,[email protected]
许可
Tsuchi 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。