mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
添加重要通知功能
close: 152
This commit is contained in:
parent
ad442cd7da
commit
089b33caa3
@ -6,6 +6,8 @@
|
||||
<string>development</string>
|
||||
<key>com.apple.developer.usernotifications.communication</key>
|
||||
<true/>
|
||||
<key>com.apple.developer.usernotifications.critical-alerts</key>
|
||||
<true/>
|
||||
<key>com.apple.developer.usernotifications.time-sensitive</key>
|
||||
<true/>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
|
||||
@ -57,7 +57,7 @@ class Client: NSObject {
|
||||
|
||||
func registerForRemoteNotifications() {
|
||||
let center = UNUserNotificationCenter.current()
|
||||
center.requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { (_ granted: Bool, _: Error?) in
|
||||
center.requestAuthorization(options: [.alert, .sound, .badge, .criticalAlert], completionHandler: { (_ granted: Bool, _: Error?) in
|
||||
if granted {
|
||||
dispatch_sync_safely_main_queue {
|
||||
UIApplication.shared.registerForRemoteNotifications()
|
||||
|
||||
@ -87,7 +87,7 @@ class HomeViewController: BaseViewController<HomeViewModel> {
|
||||
let startRequestAuthorization: () -> Observable<Bool> = {
|
||||
Single<Bool>.create { single -> Disposable in
|
||||
let center = UNUserNotificationCenter.current()
|
||||
center.requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { (_ granted: Bool, _: Error?) -> Void in
|
||||
center.requestAuthorization(options: [.alert, .sound, .badge, .criticalAlert], completionHandler: { (_ granted: Bool, _: Error?) -> Void in
|
||||
single(.success(granted))
|
||||
})
|
||||
return Disposables.create()
|
||||
|
||||
@ -43,7 +43,9 @@ class CallProcessor: NotificationContentProcessor {
|
||||
guard let content = content.mutableCopy() as? UNMutableNotificationContent else {
|
||||
return
|
||||
}
|
||||
content.sound = nil
|
||||
if !content.isCritical { // 重要通知的声音可以无视静音模式,所以别把这特性给弄没了
|
||||
content.sound = nil
|
||||
}
|
||||
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: nil)
|
||||
UNUserNotificationCenter.current().add(request)
|
||||
}
|
||||
@ -51,12 +53,10 @@ class CallProcessor: NotificationContentProcessor {
|
||||
/// 响铃结束时取消显示远程推送,因为已经用本地推送显示了一遍
|
||||
private func cancelRemoteNotification(content: UNMutableNotificationContent) {
|
||||
// 远程推送在响铃结束后静默不显示
|
||||
// 至于iOS15以下的设备,因不支持这个特性会在响铃结束后再展示一次, 但会取消声音
|
||||
// 至于iOS15以下的设备,因不支持这个特性会在响铃结束后再展示一次
|
||||
// 如果设置了 level 参数,就还是以 level 参数为准不做修改
|
||||
if #available(iOSApplicationExtension 15.0, *), self.content?.userInfo["level"] == nil {
|
||||
self.content?.interruptionLevel = .passive
|
||||
} else {
|
||||
content.sound = nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,3 +152,12 @@ class CallProcessor: NotificationContentProcessor {
|
||||
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), observer, name, nil)
|
||||
}
|
||||
}
|
||||
|
||||
extension UNMutableNotificationContent {
|
||||
var isCritical: Bool {
|
||||
if #available(iOS 15, *) {
|
||||
return self.interruptionLevel == .critical
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user