From 0d08e4021560cb6fc91bf2fbc89f6d5a8c996b95 Mon Sep 17 00:00:00 2001 From: MinhDV Date: Wed, 4 Oct 2023 11:35:19 +0700 Subject: [PATCH] TW-726 Notification no sound in iOS --- ios/Runner/AppDelegate.swift | 6 ++++++ lib/utils/background_push.dart | 8 ++++++++ lib/widgets/matrix.dart | 1 + 3 files changed, 15 insertions(+) diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 87ca5b5227..5bdffc6d0e 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -33,6 +33,12 @@ let apnTokenKey = "apnToken" case "getInitialNoti": result(self?.initialNotiInfo) self?.initialNotiInfo = nil + case "clearAll": + UIApplication.shared.applicationIconBadgeNumber = 0 + let center = UNUserNotificationCenter.current() + center.removeAllDeliveredNotifications() + center.removeAllPendingNotificationRequests() + result(true) default: break } diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 4753b082ad..4f41479eee 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -198,6 +198,8 @@ class BackgroundPush { "aps": { "mutable-content": 1, "content-available": 1, + "badge": 1, + "sound": "default", "alert": {"loc-key": "SINGLE_UNREAD", "loc-args": []} } } @@ -557,4 +559,10 @@ class BackgroundPush { return PushNotificationExtensions().error(); } } + + void clearAllNotifications() { + if (Platform.isIOS) { + apnChannel.invokeMethod('clearAll'); + } + } } diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index b290853b87..963c9cbb39 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -594,6 +594,7 @@ class MatrixState extends State with WidgetsBindingObserver { client.backgroundSync = foreground; client.syncPresence = foreground ? null : PresenceType.unavailable; client.requestHistoryOnLimitedTimeline = !foreground; + backgroundPush?.clearAllNotifications(); } void initSettings() {