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

The callback idsAvailable() exists in module RNOneSignal but only one callback may be registered #47

Closed
maxs15 opened this issue Jun 19, 2016 · 9 comments

Comments

@maxs15
Copy link
Contributor

maxs15 commented Jun 19, 2016

Hey guys,

I discovered an error that is happening when using registerForPushNotificationsand idsAvailable
I'm getting this RN error:

My code is as simple as that:

OneSignal.registerForPushNotifications();
OneSignal.configure({
  onNotificationOpened: this.onNotification,
  onError: this.onError
 });
OneSignal.idsAvailable((device) => {
  console.log('device = ', device);
});

I found out that the issue is related to the idsAvailable method in RCTOneSignal.m.
The callback registered in [oneSignal IdsAvailable:callback] is called twice (The first time without pushToken and the second time with a pushToken)
The issue is that it'll call the RN callback twice, and RN only authorize the callback to be called once in a method.

I'm trying to find a fix.. I guess we should call the idsAvailable method after the push has been successfully registered (or declined).

@avishayil, any idea how we could fix that ?

Thanks,

@avishayil
Copy link
Contributor

Thanks @maxs15 , i'll have a look on that.

@maxs15
Copy link
Contributor Author

maxs15 commented Jun 19, 2016

Thanks for such a quick reply @avishayil.
I think I just found the issue and the bug is in fact in the OneSignal Library.
Just before registering the push notifications I was asking for the user location (showing an alert to the user).
OneSignal had to wait for my location alert to close to show the push notification alert, and it looks like this is the root of the issue.
By removing my location alert, everything looks to work fine now ! :)
Hope it may help some people

@avishayil
Copy link
Contributor

Thanks @maxs15 , do you have an idea for a PR to handle this?

@maxs15
Copy link
Contributor Author

maxs15 commented Jun 21, 2016

It looks like a bug in the OneSignal IOS SDK, not sure what we could do on our side

@avishayil
Copy link
Contributor

Maybe @jkasten2 will help on this.

@maxs15
Copy link
Contributor Author

maxs15 commented Jul 2, 2016

Unfortunately it wasn't the main cause of the issue, still having some problems, but I think I finally found the issue by digging in the docs:

Note about the OneSignalIdsAvailableBlock: (https://documentation.onesignal.com/v2.0/docs/ios-sdk-api#OneSignalIdsAvailableBlock)

If you disable auto register or the user waits over 30 seconds to say yes to the system prompt then your call back will be called twice. First with just the userId field and then a 2nd time to with the push token included.

We would have to find a way to ignore this first call..

@maxs15
Copy link
Contributor Author

maxs15 commented Jul 2, 2016

I don't see any way to differentiate:

  • The call when you wait 30sec (userId populated, pushToken nil)
  • The call when the user refused the push (userId populated, pushToken nil)

Maybe we could send the idsAvailable result as an event ? (We could declare it in the configure options)

@avishayil
Copy link
Contributor

Hi @maxs15 , that sounds reasonable.

Happy if you could help and setting up a PR for that, I'm currently busy on migrating to RN 0.29 and adding all the other functions for < RN 0.28 support.

Could you help out with this issue?

@maxs15
Copy link
Contributor Author

maxs15 commented Jul 2, 2016

sure @avishayil, I'll look at that

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

2 participants