当我从以下用户通知中心委托函数调用完成处理程序并通过时,UNNotificationPresentationOptions.sound
我仍然会收到通知横幅:
override func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
completionHandler(.sound)
}
我想要的只是一种在应用程序处于前台时发出通知声音而不显示通知的方法。
有任何想法吗?
这就是我请求授权的方式:
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions: (UNAuthorizationOptionBadge | UNAuthorizationOptionSound)
completionHandler: ^ (BOOL granted, NSError * _Nullable error) {
}];
这是通知请求:
var notification = UNMutableNotificationContent()
if (notification != nil) {
notification.categoryIdentifier = "id"
notification.sound = .default
notification.title = "title"
notification.body = "body"
request = UNNotificationRequest(
identifier: NSUUID().uuidString,
content: notification,
trigger: nil
)
UNUserNotificationCenter.current().add(request) { (error) in
}