Skip to content
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

registerForPushNotifications should return a promise #53

Closed
whollacsek opened this issue Jun 28, 2016 · 8 comments
Closed

registerForPushNotifications should return a promise #53

whollacsek opened this issue Jun 28, 2016 · 8 comments
Assignees

Comments

@whollacsek
Copy link

whollacsek commented Jun 28, 2016

Please enhance registerForPushNotifications so that it will return a promise mimicking: requestPermissions

From the doc it says:

This method returns a promise that will resolve when the user accepts, rejects, or if the permissions were previously rejected. The promise resolves to the current state of the permission.

I'm searching a way to know whether the user has accepted the notification permission or not.

@avishayil
Copy link
Contributor

More than happy to accept PR for this.

@avishayil avishayil added this to the v1.1.9 milestone Jun 28, 2016
@avishayil avishayil self-assigned this Jun 28, 2016
@avishayil
Copy link
Contributor

@jkasten2 can you help on this?

@avishayil avishayil removed this from the v1.1.9 milestone Jul 4, 2016
@avishayil
Copy link
Contributor

OneSignal SDK does not allow me to do that. Also, For my best understanding, there is no way to actually know if the user accepted the push notifications dialog or not. But, it's possible to check if the notifications are enabled at a later time.
Current work on progress:

+ (BOOL)isPushNotificationsEnabled {
    BOOL isEnabled = NO;
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]){
        UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];

        if (!notificationSettings || (notificationSettings.types == UIUserNotificationTypeNone)) {
            isEnabled = NO;
        } else {
            isEnabled = YES;
        }
    } else {
        UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        if (types & UIRemoteNotificationTypeAlert) {
            isEnabled = YES;
        } else{
            isEnabled = NO;
        }
    }
    return isEnabled;
}

When you'll ask for OneSignal.isPushNotificationsEnabled it should give you an answer if notifications are enabled or not. I'm still working on it so i'm not sure it's the proper way to do that.

@avishayil
Copy link
Contributor

Well, I took some inspiration from PushNotificationsIOS and now 0b8e7e0 fixes that. You can't return a promise right now on the request permissions method, but you can check what permissions your device have, with a callback.

@whollacsek
Copy link
Author

Thanks!

@dwilt
Copy link

dwilt commented Jun 9, 2017

@avishayil so there is no way to know when the user has chosen Allow or Don't Allow?

I know we can check the current permissions with checkPermissions but how would we know when to check if we can't tell when they've responded to the modal?

image

Aren't you guys just using the native code that PushNotificationIOS is doing? Can't you use what they are? Should I just call await PushNotificationIOS.requestPermissions() myself?

Also, it would be helpful to update checkPermissions to use a promise syntax instead of a callback. Right now we're promisifying it manually:

export function checkPermissions() {
    return new Promise(resolve => {
        OneSignal.checkPermissions(resolve);
    });
}

@redwind
Copy link

redwind commented Jul 7, 2017

@dwilt you can use AppState and call OneSignal.checkPermissions again when app "active" state to get user's response

@Dexwell
Copy link

Dexwell commented Mar 3, 2018

Would really like to see Promise functionality for registerForPushNotifications. Anyone? 🙏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants