RxUserNotifications
要求
Xcode 12, Swift 5.3
安装
Swift 包管理器
RxUserNotifications 可通过 Swift 包管理器获取。要安装它,将以下行添加到您的 Package.swift
文件中的依赖项:
.package(url: "https://github.com/pawelrup/RxUserNotifications", .upToNextMinor(from: "1.1.0"))
然后添加 RxUserNotifications
到您的目标依赖项。
CocoaPods
RxUserNotifications 通过 CocoaPods 提供。要安装它,请将以下行添加到您的 Podfile
pod 'RxUserNotifications'
使用方法
简单地订阅 willPresentNotification
或 didReceiveResponse
,如下所示
let center = UNUserNotificationCenter.current()
// Presenting notification when app is in foreground.
center.rx.willPresentNotification
.subscribe(onNext: { (notification: UNNotification, completion: UNUserNotificationCenter.WillPresentNotificationCompletionHandler) in
// Do something
completion([.badge, .alert, .sound])
})
.disposed(by: disposeBag)
// Receiving user response
center.rx.didReceiveResponse
.subscribe(onNext: { (response: UNNotificationResponse, completion: UNUserNotificationCenter.DidReceiveResponseCompletionHandler) in
// Do something
completion()
})
.disposed(by: disposeBag)
作者
Paweł Rup,[email protected]
许可证
RxUserNotifications 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。