-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support delay push notification permission dialog #287
Comments
Thanks for getting in touch. Unfortunately delaying the register of |
AppCenterPushNotificationReceived
is not a supported event type for AppCenterReactNativePush. Supported events are: (null)
ok. You should probably: remove: Note that when the app calls register for the first time after being installed, iOS will prompt the user for permission to receive push notifications. If you wish to delay when that permission prompt appears to the user, say until after an app first time use wizard finishes, delay making the register call. |
Thank you @oskaratcodedesign, will update the docs. |
This is a feature I need as well, it doesn't make sense for us to show a push notification permission request as the very first thing a new user sees in our app, we want to explain why they should allow us to send them notifications. Most apps operate that way so I'm surprised this isn't something already built into the SDK. Do you think it would be possible to do the following:
The downside to this is the user will not get push notifications until they or iOS has closed the app sometime in the future and the user has restarted it. Could that potentially work in the meantime? |
Hey @codybrouwers, Thanks for getting in touch. What you suggested sounds like a good workaround with the caveat that user won't get push notifications between the time |
Proposed workaround (let me know if you see any issues with it): In // #import <AppCenterReactNativePush/AppCenterReactNativePush.h>
// [AppCenterReactNativePush register]; // Initialize AppCenter push Create #import <React/RCTBridgeModule.h>
@interface RegisterPushNotifications : NSObject <RCTBridgeModule>
@end Create #import "RegisterPushNotifications.h"
#import <AppCenterReactNativePush/AppCenterReactNativePush.h>
@implementation RegisterPushNotifications
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(register)
{
[AppCenterReactNativePush register];
}
@end Add the two files to your Xcode project. For an app named "Foo":
Task is now moved to the JS side of things, ideally you'd check with import { AsyncStorage, NativeModules } from 'react-native';
import Push from 'appcenter-push';
export const registerPushNotifications = async () => {
const shouldRegister = await AsyncStorage.getItem('shouldRegister');
if (shouldRegister) {
NativeModules.RegisterPushNotifications.register();
Push.setListener({ /* .. */ });
}
};
export const askForPushNotificationsPermission = async () => {
await AsyncStorage.setItem('shouldRegister', 'yes');
registerPushNotifications();
};
// appDidMount
componentDidMount() {
registerPushNotifications();
}
<Button title="Hi" onPress={askForPushNotificationsPermission} /> I would like to see this supported out of the box, such an essential feature. |
We unfortunately don't have an ETA for this feature request but I forwarded this feedback to the team. The solution looks good to me for iOS. For Android, there should not be this UI as the custom module is undefined in the proposed solution so make sure this code is used only on iOS. |
Yes this is iOS only, already deployed and tested, it works great. I can add that It make sense to have it follow the same convention similar to Automatic/JS options in Analytics and Crashes, to avoid breaking the current implementation (Automatic only). |
@sonaye 's solution is fantastic, works great for me. Still, it would be nice to have control over how permission is requested, not just when. Is there a way to know whether the user clicked "yes" when prompted for permission? I have my app structured so that the user clicks "allow push" with a button I created, the app then calls AppCenterReactNativePush using @sonaye 's solution. This clumsily requires the user to click "allow" a second time in the alert message, but I guess that will do. But, if she clicks "no" in this dialogue, do I have some way of knowing this? If she clicks "allow" in my app, then changes her mind and clicks "no" in the alert, things could get very confusing. |
@JasonFehr Unfortunately there is no way to detect user selections on permission dialog. |
You can actually check if notifications are enabled with what options. |
@sonaye - thank you for the solution to iOS! Did you also solve it for Android or do you have an idea how to do it? |
The feature is released in 1.11.0. It works differently than the workarounds. The documentation is being published but here is a copy: iOSIf you want to delay requesting Push notifications permission the first time the application is run:
After calling AndroidIf you want to delay Push initialization the first time the application is run:
After calling |
We want to delay AppCenterReactNativePush register, so notification permission is not asked at startup. But it doesnt work:
if Push.setListener({onPushNotificationReceived: pushNotification => {
is called before AppCenterReactNativePush register is finished =
Crash
AppCenterPushNotificationReceived
is not a supported event type for AppCenterReactNativePush. Supported events are:(null)
AppCenterReactNativePush needs to be initialized?
Repro Steps
Please list the steps used to reproduce your issue.
or
and call Push.setListener({onPushNotificationReceived: pushNotification => { })
= either crash or onPushNotificationReceived is never received.
or
1 If you delay the Push.setListener({onPushNotificationReceived: pushNotification => { }), it doesnt crash, but then onPushNotificationReceived is never received?
Details
What third party libraries are you using?
react-native info
Environment:
OS: macOS High Sierra 10.13.4
Node: 9.3.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.3 Build version 9E145
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
react: ^16.3.0-alpha.1 => 16.3.0-alpha.1
react-native: 0.54.2 => 0.54.2
pod --version
1.5.0
The text was updated successfully, but these errors were encountered: