Skip to content

Access to AuthorizationStatus on iOS #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
artdevgame opened this issue Feb 10, 2022 · 2 comments
Closed

Access to AuthorizationStatus on iOS #811

artdevgame opened this issue Feb 10, 2022 · 2 comments

Comments

@artdevgame
Copy link
Contributor

Hello 👋🏻

Other push notification libraries give us access to the AuthorizationStatus (or something similar) that allows us to determine if the user has previously seen the permission dialog and accepted/denied notifications, or if they haven't seen them at all.

I need this functionality in my app as I like to show an info card before requesting permissions in the UI.

This is the functionality we have exposed at the moment:

// boolean
const isRegisteredForPush = await Notifications.isRegisteredForRemoteNotifications(); 

/*
export interface NotificationPermissionOptions {
    carPlay?: boolean;
    criticalAlert?: boolean;
    providesAppNotificationSettings?: boolean;
    provisional?: boolean;
    announcement?: boolean;
}
export interface NotificationPermissions extends NotificationPermissionOptions {
    badge: boolean;
    alert: boolean;
    sound: boolean;
    notificationCenter: boolean;
    lockScreen: boolean;
}
*/

// NotificationPermissions
const permissions = await Notifications.ios.checkPermissions();

I'm incapable of determining an undetermined state 😄

if (!isRegisteredForPush) {
	// is this because they denied access or because they haven't seen the permission dialog yet?
}

if (!permissions.alert && !permissions.provisional) {
	// is this because we don't have the necessary permissions, or because they haven't seen the permission dialog yet?
}

Here's an example of how @firebase-react-native/messaging expose it:
https://github.com/invertase/react-native-firebase/blob/49d5bedea52683fa98db5f90d3243fe770c4cad5/packages/messaging/lib/index.d.ts#L461

And another from @react-native-community/push-notification-ios:
https://github.com/react-native-push-notification/ios/blob/88b49f9b548825df9e74ebcf582a9320742c7d54/index.d.ts#L11

I would like it exposed both as a type and const so I can use it both for type-checking and assignment.

@DanielEliraz
Copy link
Collaborator

DanielEliraz commented Feb 14, 2022

Hey @artdevgame, your users will see the dialog only after you'll operate Notifications.registerRemoteNotifications(). So you can know if you did that before, no?
You may save a boolean whether you asked it in a storage like @react-native-community/async-storage.
I think the reason we don't have it is because Android lacks it. But it can be a nice PR someday 😃

@artdevgame
Copy link
Contributor Author

@DanielEliraz I didn't think to use local-storage to work around the issue, yep, that will work, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants