Skip to content

Commit

Permalink
fix(messaging, ios): Support Ephemeral authorization state (#6478)
Browse files Browse the repository at this point in the history
* fix(messaging, ios): Support Ephemeral authorization state

* fix(messaging, ios): expand ephemeral check to cover macCatalyst

* style(messaging, lint): `yarn lint:ios:fix`

Co-authored-by: Mike Hardy <[email protected]>
  • Loading branch information
navro and mikehardy authored Aug 26, 2022
1 parent 630142f commit 795b684
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/messaging/ios-permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ The value returned is a number value, which can be mapped to one of the followin
- `0` = `messaging.AuthorizationStatus.DENIED`: The user has denied notification permissions.
- `1` = `messaging.AuthorizationStatus.AUTHORIZED`: The user has accept the permission & it is enabled.
- `2` = `messaging.AuthorizationStatus.PROVISIONAL`: [Provisional authorization](#provisional-authorization) has been granted.
- `3` = `messaging.AuthorizationStatus.EPHEMERAL`: The app is authorized to create notifications for a limited amount of time. Used for app clips.

To help improve the chances of the user granting your app permission, it is recommended that permission is requested at a time which makes
sense during the flow of your application (e.g. starting a new chat), where the user would expect to receive such notifications.
Expand Down
6 changes: 6 additions & 0 deletions packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ - (NSDictionary *)constantsToExport {
}
}

if (@available(iOS 14.0, macCatalyst 14.0, *)) {
if (settings.authorizationStatus == UNAuthorizationStatusEphemeral) {
authorizedStatus = @3;
}
}

resolve(authorizedStatus);
}];
} else {
Expand Down
7 changes: 7 additions & 0 deletions packages/messaging/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,13 @@ export namespace FirebaseMessagingTypes {
* @platform ios iOS >= 12
*/
PROVISIONAL = 2,

/**
* The app is authorized to create notifications for a limited amount of time.
* Used in App Clips.
* @platform ios iOS >= 14
*/
EPHEMERAL = 3,
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/messaging/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const statics = {
DENIED: 0,
AUTHORIZED: 1,
PROVISIONAL: 2,
EPHEMERAL: 3,
},
NotificationAndroidPriority: {
PRIORITY_MIN: -2,
Expand Down

1 comment on commit 795b684

@vercel
Copy link

@vercel vercel bot commented on 795b684 Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.