Git Product home page Git Product logo

Comments (8)

Dexwell avatar Dexwell commented on July 20, 2024 11

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

from react-native-onesignal.

redwind avatar redwind commented on July 20, 2024 3

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

from react-native-onesignal.

avishayil avatar avishayil commented on July 20, 2024

More than happy to accept PR for this.

from react-native-onesignal.

avishayil avatar avishayil commented on July 20, 2024

@jkasten2 can you help on this?

from react-native-onesignal.

avishayil avatar avishayil commented on July 20, 2024

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.

from react-native-onesignal.

avishayil avatar avishayil commented on July 20, 2024

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.

from react-native-onesignal.

whollacsek avatar whollacsek commented on July 20, 2024

Thanks!

from react-native-onesignal.

dwilt avatar dwilt commented on July 20, 2024

@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);
    });
}

from react-native-onesignal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.