Skip to content

Commit 2858d74

Browse files
authored
fix(messaging): request all permissions regardless of the configured presentation options (#826)
* fix(messaging): request all permissions regardless of the configured presentation options * wip
1 parent 11953fd commit 2858d74

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

.changeset/quiet-files-pump.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@capacitor-firebase/messaging': patch
3+
---
4+
5+
fix(ios): request all permissions regardless of the configured presentation options

packages/messaging/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ On iOS you can configure the way the push notifications are displayed when the a
106106

107107
| Prop | Type | Description | Default | Since |
108108
| ------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | ----- |
109-
| **`presentationOptions`** | <code>PresentationOption[]</code> | This is an array of strings you can combine. Possible values in the array are: - `badge`: badge count on the app icon is updated (default value) - `sound`: the device will ring/vibrate when the push notification is received - `alert`: the push notification is displayed in a native dialog - `criticalAlert`: the push notification is displayed in a native dialog and bypasses the mute switch An empty array can be provided if none of the options are desired. Only available for iOS. | <code>["badge", "sound", "alert"]</code> | 0.2.2 |
109+
| **`presentationOptions`** | <code>PresentationOption[]</code> | This is an array of strings you can combine. Possible values in the array are: - `badge`: badge count on the app icon is updated (default value) - `sound`: the device will ring/vibrate when the push notification is received - `alert`: the push notification is displayed in a native dialog - `criticalAlert`: the push notification is displayed in a native dialog and bypasses the mute switch An empty array can be provided if none of the options are desired. Only available for iOS. | <code>["alert", "badge", "sound"]</code> | 0.2.2 |
110110

111111
### Examples
112112

@@ -116,7 +116,7 @@ In `capacitor.config.json`:
116116
{
117117
"plugins": {
118118
"FirebaseMessaging": {
119-
"presentationOptions": ["badge", "sound", "alert"]
119+
"presentationOptions": ["alert", "badge", "sound"]
120120
}
121121
}
122122
}
@@ -132,7 +132,7 @@ import { CapacitorConfig } from '@capacitor/cli';
132132
const config: CapacitorConfig = {
133133
plugins: {
134134
FirebaseMessaging: {
135-
presentationOptions: ["badge", "sound", "alert"],
135+
presentationOptions: ["alert", "badge", "sound"],
136136
},
137137
},
138138
};

packages/messaging/ios/Plugin/FirebaseMessaging.swift

+5-13
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,11 @@ import FirebaseCore
2323

2424
public func requestPermissions(completion: @escaping (_ granted: Bool, _ error: Error?) -> Void) {
2525
var options = UNAuthorizationOptions()
26-
self.config.presentationOptions.forEach { option in
27-
switch option {
28-
case "alert":
29-
options.insert(.alert)
30-
case "badge":
31-
options.insert(.badge)
32-
case "sound":
33-
options.insert(.sound)
34-
case "criticalAlert":
35-
options.insert(.criticalAlert)
36-
default:
37-
print("Unrecogizned authorization option: \(option)")
38-
}
26+
options.insert(.alert)
27+
options.insert(.badge)
28+
options.insert(.sound)
29+
if self.config.presentationOptions.contains("criticalAlert") {
30+
options.insert(.criticalAlert)
3931
}
4032
UNUserNotificationCenter.current().requestAuthorization(options: options) { granted, error in
4133
completion(granted, error)

packages/messaging/src/definitions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ declare module '@capacitor/cli' {
2121
*
2222
* Only available for iOS.
2323
*
24-
* @example ["badge", "sound", "alert"]
25-
* @default ["badge", "sound", "alert"]
24+
* @example ["alert", "badge", "sound"]
25+
* @default ["alert", "badge", "sound"]
2626
* @since 0.2.2
2727
*/
2828
presentationOptions: PresentationOption[];

0 commit comments

Comments
 (0)