Amplify-js: Amplify on launch requests permission for notifications, which is undesirable

Created on 28 Sep 2018  路  11Comments  路  Source: aws-amplify/amplify-js

Describe the bug
When launching an iOS React Native application the user is immediately asked to enable push notifications. This happens, I believe, because Amplify.configure() eventually calls PushNotification.initializeIOS().

To Reproduce
Create an iOS React Native application and run Amplify.configure().

Expected behavior
Request permission to send notifications later, when needed. e.g., after an onboarding flow, sign-in, etc.

Smartphone (please complete the following information):

  • Device: iPhone 8
  • OS: iOS 12.0

Additional context

It would be nice if this were removed from PushNotification.initializeIOS():

PushNotificationIOS.requestPermissions({
  alert: true,
  badge: true,
  sound: true
});

And instead were a separate method (e.g., PushNotification.requestPermissionsIOS().

Push Notifications feature-request

Most helpful comment

I submitted my own PR #2697 to add this functionality because my team also needs it for our app. I used the config option approach to maintain backward compatibility as requested. Please let me know if it looks ok, @powerful23

The way it works is that you configure PushNotification to not automatically request permissions:

PushNotification.configure({ requestIOSPermissions: false });

Then later when you are ready to request the permission, you can manually call this method:

PushNotification.requestIOSPermissions();

After you allow the permission in the app, the device token will be received by the library.

Hope this helps.

All 11 comments

@KylePalko thanks for your feedback. Will mark as feature request.

Awesome, I can submit a PR if that would be helpful?

@KylePalko of course you can submit one for that. But one thing is that can you try to keep the backward compatibility so that it won't break the current default behavior? Thanks.

@powerful23, good idea.

Would you imagine they pass through a configuration to initializeIOS() to preserve backward compatibility? Something like,

PushNotification.initializeIOS({
  requestPermissions: false // defaults to true for backwards compatibility
})

@KylePalko exactly, I would prefer an option in the configuration.

That works, will do!

Any progress with this? 馃榾

I submitted my own PR #2697 to add this functionality because my team also needs it for our app. I used the config option approach to maintain backward compatibility as requested. Please let me know if it looks ok, @powerful23

The way it works is that you configure PushNotification to not automatically request permissions:

PushNotification.configure({ requestIOSPermissions: false });

Then later when you are ready to request the permission, you can manually call this method:

PushNotification.requestIOSPermissions();

After you allow the permission in the app, the device token will be received by the library.

Hope this helps.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I believe this issue has been resolved by my PRs merged above. The behavior can be modified as per the new documentation: https://github.com/aws-amplify/docs/pull/643/files

Resolving as the implementation has been done along with the documentation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rygo6 picture rygo6  路  3Comments

rayhaanq picture rayhaanq  路  3Comments

romainquellec picture romainquellec  路  3Comments

leantide picture leantide  路  3Comments

callmekatootie picture callmekatootie  路  3Comments