Meteor-Community-Packages / raix-push

DEPRECATED: Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox)
https://atmospherejs.com/raix/push
MIT License
514 stars 197 forks source link

How to: manually initialise native notifications permission dialog #282

Closed markodvornik closed 7 years ago

markodvornik commented 7 years ago

Hi, I'm looking for a way to manually initialise the native notifications permission dialog.

The use case for that is when a user denies notification permissions on the first run (when the plugin shows that native confirmation dialog), but later changes his mind and would give those permission if asked. At the moment the plugin doesn't ask the user for the permissions on successive runs (cold or warm).

User can enable notifications in device settings, but I would like to give a user an option to do that within the app interface in the same style as it is done at the first run of the app (with native dialog).

This is how I test if the app has notification permissions. It works most of the time.

PushNotification.hasPermission(function(data) {
   if (data.isEnabled) {
    // true
    // do nothing
  } else {
    // false
    // trigger native modal
  }
  console.log("test enabled", data.isEnabled);
});

If that returns false I can present e.g. a button to the user with an action to initialise the native push permission dialog

I think that this process of initialisation is bound to the 'Puch.Configure' method, but that can't be run more than once so I can't use it. I also tried with cordova plugin API 'PushNotification.init', but to no avail.

So, is there a way to bound a permission initialisation to a button in the app interface?

indesignlatam commented 7 years ago

On iOS I think if a user don't allow push notifications in the first attempt it can't be done again by showing the permission alert, you have to ask the user to change this on the settings.

The only thing you can do is, if the user has no token (declined) show him every time he starts the app a modal or any view showing the steps to enable push.

-- EDIT -- This article has a good workaround. https://clevertap.com/blog/asking-for-ios-push-notification-permissions/

markodvornik commented 7 years ago

@indesignlatam thanks for the link. I agree with the soft approach in the article, however it is not applicable in this case.

System alert is bound to cordova-push-plugin.init which is called by the Push.Configure which is called at the Meteor.startup. So in the case of raix:push we can't delay system dialogue to a later time and thus improve click rate. Please correct me if I'm mistaken.

As for the problem at hand, I believe you are right, this can't be done.

From the Apple docs:

The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.

There's no mention of a second or third alert.

I'll close this as a non-issue. However, if there's a way to postpone the system alert, I'd appreciate any hint in that regard.

indesignlatam commented 7 years ago

Your right, it would be better if the request for permission was not done at startup, I don't remember if this package has an option for that. Im only using this package for our old blaze mobile apps.

You should open another issue asking for that feature. I think is a common practice, maybe it can be done but is not documented.

markodvornik commented 7 years ago

I think this is a cordova-push-plugin feature. I recently ran into a thread on their forums regarding this issue and it is still not resolved. Also, it looks that raix:push is no longer in active development so I think it makes more sense to switch to another plugin or service for push notifications.

indesignlatam commented 7 years ago

Im now working with Meteor + React native for mobile apps. I recommend you to take a look for one signal. I don't know if there are packages for Meteor or Cordova but with RN it works great.

https://onesignal.com