Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Know when the notification permission was accepted #32

Open
guilhermebruzzi opened this issue Dec 6, 2016 · 4 comments
Open

Know when the notification permission was accepted #32

guilhermebruzzi opened this issue Dec 6, 2016 · 4 comments

Comments

@guilhermebruzzi
Copy link
Contributor

Hi @rlepinski ,

I will create a pull request on this project, that will enable the possibility to know on javascript when the user accepted the notification permission's dialog on iOS and Android 6+.

On iOS there is a didRegisterForRemoteNotificationsWithDeviceToken method that you can declare on AppDelegate.m and you will receive there if the user confirmed the notification permission's dialog.

On Android there is a onRequestPermissionsResult method of an Activity, that you can declare to know if a user confirmed a permission dialog that you called on a given Activity (https://developer.android.com/training/permissions/requesting.html#perm-check).

The problem is knowing how to get the permission's result on Android 6+, if is the Urban Airship SDK that controls this permission's request.
There is some sort of callback that Urban Airship Android's SDK give, that I can use to know if a user accepted the notification permission's dialog? Or any other way to know that?

Thank you in advance for your time! :D

@rlepinski
Copy link
Collaborator

rlepinski commented Dec 7, 2016

Starting with iOS 8 they separated APNS registration (device token) with notificaiton permissions. Its actually entirely possible to message a device using APNS before the user accepts permissions if they have background notification capabilities enabled. The actual way to check for the permission is to check for the app delegate application:didRegisterUserNotificationSettings on iOS 8-9, but iOS 10 it gets a bit trickier. They deprecated UIUserNotificationSettings and introduced NSUserNotificationCenter which has no delegate callbacks for when settings change. Instead you get the result when you attempt to register for settings. However we added a registration delegate method that we will call anytime we detect a change in authorized types for iOS 8-10: http://docs.urbanairship.com/reference/libraries/ios/latest/Protocols/UARegistrationDelegate.html#/c:objc(pl)UARegistrationDelegate(im)notificationAuthorizedOptionsDidChange: For iOS, I would use that to handle user acceptance in a backwards compatible way.

For Android, there is actually no permissions required to receive and post notifications :). The user can disable notifications in the application setting screen, which you can check with http://docs.urbanairship.com/reference/libraries/android/latest/reference/com/urbanairship/push/PushManager.html#isOptIn(). You can check if it changes whenever the app is resumed (they have to background the app to disable it).

@guilhermebruzzi
Copy link
Contributor Author

Great @rlepinski, thank you! :D

@mkko
Copy link

mkko commented Dec 12, 2016

So, @guilhermebruzzi, are you working on this? We'd need to have the UARegistrationDelegate exposed on the React Native side as well, so I'm interested to put some effort into this as well.

guilhermebruzzi added a commit that referenced this issue Dec 12, 2016
…and explaining on README how to know on ios when the user accepted the notification.

Update documentation
@guilhermebruzzi
Copy link
Contributor Author

Hi @mkko, I've just sent a PR #33
For our needs to work on iOS 9, iOS 10 and Android 4.1+ (which already have notification permission accepted), this solves the problem.
Do you and @rlepinski think it's a good solution?

emilianoeloi pushed a commit that referenced this issue Mar 7, 2017
…and explaining on README how to know on ios when the user accepted the notification.

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

No branches or pull requests

3 participants