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):
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()
.
@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
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:
Then later when you are ready to request the permission, you can manually call this method:
After you allow the permission in the app, the device token will be received by the library.
Hope this helps.