Tsuchi
Tsuchi is awesome Firebase Cloud Messaging wrapper.
You can handle FCM easily and type-safely.
Usage
Register/Unregister Notification
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
//...
}
}
Subscribe Push Notification
-
- Create Payload Model (must conform to
PushNotificationPayload
)
- Create Payload Model (must conform to
struct FCMNotificationPayload: PushNotificationPayload {
let eventName: String?
let eventType: EventType?
var aps: APS?
}
-
- call
Tsuchi.subscibe(_:completion)
- call
Tsuchi.shared.subscribe(FCMNotificationPayload.self) { result in
switch result {
case .success(let (notification, mode)):
print(notification.name, mode)
case .failure(let error):
print(error)
}
}
Subscribe/UnSubscribe Topic
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
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
Installation
Tsuchi is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Tsuchi'
Author
miup, [email protected]
License
Tsuchi is available under the MIT license. See the LICENSE file for more info.