Skip to content

Commit 26d2fe2

Browse files
authored
Merge pull request #1785 from devPaidion/main
[Messaging] Fix deprecated UNNotificationPresentationOptions (#1784)
2 parents aac34aa + affa148 commit 26d2fe2

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

messaging/MessagingExample/AppDelegate.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,15 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
122122
NSLog(@"%@", userInfo);
123123

124124
// Change this to your preferred presentation option
125-
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert);
125+
// Note: UNNotificationPresentationOptionAlert has been deprecated.
126+
if (@available(iOS 14.0, *)) {
127+
completionHandler(UNNotificationPresentationOptionList |
128+
UNNotificationPresentationOptionBanner |
129+
UNNotificationPresentationOptionSound);
130+
} else {
131+
completionHandler(UNNotificationPresentationOptionAlert |
132+
UNNotificationPresentationOptionSound);
133+
}
126134
}
127135

128136
// Handle notification messages after display notification is tapped by the user.

messaging/MessagingExampleSwift/AppDelegate.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,13 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
119119
print(userInfo)
120120

121121
// Change this to your preferred presentation option
122-
return [[.alert, .sound]]
123-
}
122+
// Note: UNNotificationPresentationOptions.alert has been deprecated.
123+
if #available(iOS 14.0, *) {
124+
return [.list, .banner, .sound]
125+
} else {
126+
return [.alert, .sound]
127+
}
128+
}
124129

125130
func userNotificationCenter(_ center: UNUserNotificationCenter,
126131
didReceive response: UNNotificationResponse) async {

0 commit comments

Comments
 (0)