React-native-onesignal: request iOS permissions again after Deny

Created on 30 Mar 2017  Â·  9Comments  Â·  Source: OneSignal/react-native-onesignal

If user selects 'DENY' when initially asked to allow push notifications, how can we re-prompt them later if they explicitly try to re-enable them using our UI?

Note - We are not explicitly doing kOSSettingsKeyAutoPrompt:@NO in AppDelegate so I assume it is defaulting to YES.. The prompt comes up when initially install+first running the app. If user selects DENY, we have a Settings option to allow them to re-enable it. However, doing OneSignal.registerForPushNotifications or OneSignal. registerForPushNotifications seems to have no effect.

Most helpful comment

PushNotificationIOS method returns a Promise indicating if the user has denied or accepted the push notification modal. Can we have the same behavior in this library as well?

https://facebook.github.io/react-native/docs/pushnotificationios.html#requestpermissions

All 9 comments

AFIK this is not possible on iOS, it is outside of this package. What you
can do however is check the status and show a link to the Settings screen.
If you want I can look for a code snippet how we handled this in our app.
On Thu, 30 Mar 2017 at 07:39, dguillamot notifications@github.com wrote:

If user selects 'DENY' when initially asked to allow push notifications,
how can we re-prompt them later if they explicitly try to re-enable them
using our UI?

Note - We are not explicitly doing kOSSettingsKeyAutoPrompt:@NO
https://github.com/NO in AppDelegate so I assume it is defaulting to
YES.. The prompt comes up when initially install+first running the app. If
user selects DENY, we have a Settings option to allow them to re-enable it.
However, doing OneSignal.registerForPushNotifications or OneSignal.
registerForPushNotifications seems to have no effect.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/geektimecoil/react-native-onesignal/issues/232, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAMWSBRozB1BcjXfCA7T79ASaJMHQ3ymks5rq0AngaJpZM4Mt41L
.

@jeroenbourgois
I see.. Thanks! Hmm. Unfortunate that it's not included in this package, as now a native release might be required to work around it. Would not all users of this package have the same issue whenever their users DENY pushes? I guess noone is trying to re-enable it? I suppose we could argue that it's outside of the scope of this package since this is one signal only, but since it is a push notification package it might be nice to have as an add-on maybe.

I see i the iOS settings there is a Notification Area that lists various apps, and ours with 'Off' listed (when user selects DENY).

Do you have a way to detect that it is set to off? And, do you redirect the user directly to that screen to toggle it? I believe there is a way to do redirect into setting screens, although that is almost definitely going to be native code.

I see requestPermissions and checkPermissions here - https://facebook.github.io/react-native/docs/pushnotificationios.html

for PushNotificationIOS .. this API looks very similar to the react-native-onesignal one.. I wonder if that will cause any conflicts.

@dguillamot It is indeed on the OS level this is handled, RN has no way of triggering the modal again. You can indeed link to the settings screen, it provides you with the settings screen directly for you app, works well.

In our App location is mandatory, so whenever the AppState changes we check the permissions, you could do this at another given moment.

// somewhere inside a component or another lifecycle...
this.props.dispatch(checkPermission('location'))

// then in the actions (we use redux, you do not need to)
import Permissions from 'react-native-permissions'

export const checkPermission = (permissionType: PermissionTypeType): ThunkAction => {
  return (dispatch: Dispatch) => {
    Permissions.requestPermission('location', 'always')
      .then((permissionStatus: PermissionStatusType) => {
        if(permissionStatus !== 'authorized') {
           // here we dispatch an action to show another screen where we provide some
           // info to the user why we need their location, and then we should a button
           // that guides them to the settings page. In the end we call this:
           Permissions.openSettings()
        }
      })
  }
}

see the docs for the different status types. The screen presented is something like this:
image

@dguillamot has this worked for you? We can close this issue nonetheless I guess?

@jeroenbourgois We are going to try this as part of our next Native update but have not done so yet. I will close this issue now though, thank you.

you could also open the iOS setting page by calling Linking.openURL

    if (this.state.denyPushNotificationPermission) {
      Linking.openURL('app-settings:').catch((err) => {
        console.log(err);
      });
    }

PushNotificationIOS method returns a Promise indicating if the user has denied or accepted the push notification modal. Can we have the same behavior in this library as well?

https://facebook.github.io/react-native/docs/pushnotificationios.html#requestpermissions

^ seems squarely in this lib's domain, any arguments against adding this?

Was this page helpful?
0 / 5 - 0 ratings