React-native-onesignal: (v3.2.1) (iOS) pushToken null on real device

Created on 14 May 2018  ·  36Comments  ·  Source: OneSignal/react-native-onesignal

Description:
Cannot get pushToken, no one ios users on dashboard, I try evething, I recreate certificates, keys, use provisioning tools, try on diffrent real devices.

On android everything works like a charm.

Environment

  1. What version of the OneSignal React-Native SDK are you using: latest 3.2.1
  2. How did you add the SDK to your project (eg. npm) npm i --save react-native-onesignal
  3. [email protected]
  4. Xcode Version 9.3 (9E145)
  5. Node.js 8.4.0

my package.json

package json rbtse 2018-05-14 11-59-05

Steps to Reproduce Issue:

  1. Follow all possible variants in intruction on onesignal.com
  2. Add js code from example folder in this repo
  3. Test on real devices (iphone x with ios 11, iphone 6s with ios 10)

js code

export default class App extends Component {
  componentWillMount() {
    OneSignal.setLogLevel(7, 0);
    OneSignal.init('here my ONESIGNAL APP ID - I checked it twenty times', { kOSSettingsKeyAutoPrompt: true });
    OneSignal.setSubscription(true);
    OneSignal.enableSound(true);
    OneSignal.enableVibrate(true);
    OneSignal.inFocusDisplaying(2);

    OneSignal.getPermissionSubscriptionState((response) => {
      console.log('Received permission subscription state: ', response);
    });
  }

I got response from getPermissionSubscriptionState:

{
  emailAddress:null
  emailSubscribed:false
  emailUserId:null
  hasPrompted:true
  notificationsEnabled:true
  pushToken:null
  subscriptionEnabled:false
  userId:null
  userSubscriptionEnabled:true
}

Of course no one ios user on dashboard.

Additional I see logs in xcode

Called init with app ID: (null)
2018-05-14 11:21:03.636571+0300 rbtse[15320:6135130] Called init with app ID: xxxxxx-ea78-4b29-8b91-xxxxxxxxx (I changed app id)
2018-05-14 11:21:03.636758+0300 rbtse[15320:6135130] DEBUG: Downloading iOS parameters for this application
2018-05-14 11:21:03.642023+0300 rbtse[15320:6135181] VERBOSE: getNotificationTypes:mSubscriptionStatus: -1
2018-05-14 11:21:03.643531+0300 rbtse[15320:6135130] VERBOSE: registerForPushNotifications Called:waitingForApnsResponse: 1
2018-05-14 11:21:03.690752+0300 rbtse[15320:6135130] VERBOSE: oneSignalApplicationWillResignActive
2018-05-14 11:21:03.986984+0300 rbtse[15320:6135181] VERBOSE: network response (OSRequestGetIosParams): {
    fba = 1;
}
2018-05-14 11:21:05.778574+0300 rbtse[15320:6135130] VERBOSE: oneSignalApplicationDidBecomeActive
2018-05-14 11:21:05.778918+0300 rbtse[15320:6135130] VERBOSE: getNotificationTypes:mSubscriptionStatus: -1
2018-05-14 11:21:05.792324+0300 rbtse[15320:6135130] VERBOSE: updateNotificationTypes called: 15
2018-05-14 11:21:05.792388+0300 rbtse[15320:6135130] VERBOSE: startedRegister: 1

Most helpful comment

Hi everyone @dooboolab @hhunaid @408dev @el-lsan @neo125874 @Jarred-Sumner

The new update (3.2.3) has been released and should fix this issue. Please feel free to let me know if you see this issue (or other issues) again and I'll be happy to investigate.

All 36 comments

I found the same problem https://github.com/geektimecoil/react-native-onesignal/issues/502
So I try to downgrade to https://github.com/geektimecoil/react-native-onesignal/tree/3.1.4 - follow all steps and now it works!

react native debugger - connected port 8081 2018-05-14 12-24-59

users rbtse onesignal 2018-05-14 12-27-59

So last version isn`t working

Hi, when you install the latest version of react-native-onesignal (3.2.2) and run react-native link react-native-onesignal, can you open the Xcode project and verify that RCTOneSignal correctly shows up as a dependency in your project like this?

alt text

pushToken and userId are null for me on real devices as well (in release mode)
image

[email protected]:
  version "3.2.2"
  resolved "https://registry.yarnpkg.com/react-native-onesignal/-/react-native-onesignal-3.2.2.tgz#d1ae1e95cc301b940120de29a29ae90f478c9a97"
  dependencies:
    invariant "^2.2.2"

(its not in my podfile this time)

@Jarred-Sumner Try uninstalling the app from your device, then re-install it, does it prompt you to accept push notification permissions?

Also, just to check, you did enable the Push Notifications capability in Project Settings > Capabilities, correct?

@Jarred-Sumner Try uninstalling the app from your device, then re-install it, does it prompt you to accept push notification permissions?

Yes

Also, just to check, you did enable the Push Notifications capability in Project Settings > Capabilities, correct?

Yes
image
image

I downgraded to v3.1.4 and now it sends the pushToken and userId

@Jarred-Sumner Just to understand this issue a bit better, the ID's are null, but do push notifications actually work? They shouldn't, but I wanted to double check.

Also, can you try updating to 3.2.2, initialize with JS, and call OneSignal.setLogLevel(6, 0) before you call init. Can you tell me if you see any errors printed to console?

Issue persists on 3.2.2.
Setting the log level prints following output

Called init with app ID: (null)
(Then somewhere below in logs)
Called init with app ID: (my-app-id)

But userId is still null. I have included the library using CocoaPods if that helps

@hhunaid it is expected that the app ID will be null the first time (perhaps we should remove that first log statement to avoid confusion).

It is also expected that user ID will be null until the user accepts push permission on a real iOS device. Can you confirm this is the case? If so, can you post a link to at least 15 seconds of log output from Xcode with that log level (make sure to call setLogLevel before calling init)

@Nightsd01 it's not just the LOG statement. There is actually a call to OneSignal initializer with null appId. I just checked that if I remove that init line in initOneSignal method everything works.

@hhunaid yes, it is expected that the first call to the initializer will be with a null App ID, this is how many of our wrapper SDK’s work. You are saying that if you remove this first call, “everything works”...?

In order to rule out other changes you may have made, can you uncomment initOneSignal again to verify it stops working...?

Can you post your package.json so I can see what dependencies you’re using?

I have tried on and off with and without the mentioned piece of code and now I can say with confidence that indeed it is the culprit. At least in my app.
Removing it gives me a valid playerId and my device shows on OneSignal dashboard. Which was not happening before.

Same here. PushToken is always null. I'll paste the screenshot below.
screen shot 2018-05-16 at 3 55 07 am

my package.json is as below.

    "abortcontroller-polyfill": "^1.1.9",
    "immutability-helper": "^2.7.0",
    "mobx": "^4.2.1",
    "mobx-react": "^5.1.2",
    "moment": "^2.22.1",
    "react": "^16.3.2",
    "react-native": "^0.55.4",
    "react-native-amplitude-analytics": "^0.1.15",
    "react-native-animatable": "^1.2.4",
    "react-native-audio-recorder-player": "^1.0.15",
    "react-native-iap": "^1.0.1",
    "react-native-image-picker": "^0.26.10",
    "react-native-linear-gradient": "^2.4.0",
    "react-native-loading-spinner-overlay": "^0.5.2",
    "react-native-localization": "^1.0.7",
    "react-native-marquee": "^0.3.1",
    "react-native-modalbox": "^1.4.2",
    "react-native-onesignal": "^3.2.2",
    "react-native-permissions": "^1.1.1",
    "react-native-pinch-zoom-view": "^0.1.6",
    "react-native-sentry": "^0.36.0",
    "react-native-status-bar-height": "^2.0.0",
    "react-native-swiper": "^1.5.13",
    "react-navigation": "^2.0.1",
    "serializr": "^1.2.0"

@dooboolab You are using JS initialization, correct?

Can you tell me where in your project you are calling OneSignal.init()?

For the life of me I _cannot_ reproduce this issue. If someone could reproduce this issue in a demo project and post it we'd be able to fix this issue _much_ faster.

@tavriaforever hi, so downgrade & call onesignal.init('app id') would work?

same issue here, any solution ?

    "react": "16.3.1",
    "react-native": "0.55.3",
    "react-native-onesignal": "^3.2.0",

@Nightsd01
I am calling in my root index.tsx where it wraps RootStackNavigator.

class App extends React.Component {
  public componentDidMount() {
    OneSignal.init('****');
    OneSignal.addEventListener('received', this.onReceived);
    OneSignal.addEventListener('opened', this.onOpened);
    OneSignal.addEventListener('ids', this.onIds);
    OneSignal.enableVibrate(true);
    OneSignal.enableSound(true);

.....
public render() {
    return (
      <Provider
        store={ appStore }
        user={ userStore }
        player={ playerStore }
      >
        <View style={styles.container}>
          <RootStackNavigator />
        </View>
      </Provider>
    );

Still suffering from getting null token.

@Nightsd01 Same here.
Removing init with appId:nil in RCTOneSignal.m helped

@Nightsd01 I just tried on android, and android have same problem.

I guess JS-side initialization was not such a great idea.
I understand though that it makes it easier for web devs or people with no native background to easily use the library.

@hhunaid sounds like I should downgrade?

@dooboolab @408dev yes, I would recommend that if you're encountering this issue, you downgrade to 3.1.4 for the time being until we sort this issue out. Apologies. Keep in mind that JS init was not supported in 3.1.4 so you will want to follow the guide to add the native initialization code to your project.

@hhunaid it does indeed make things easier for react devs.

As an update, we've been able to reproduce this issue and have identified the cause, we'll be rolling out an update to resolve it soon.

Hi everyone - this issue has been resolved in a new PR (#512). We expect to have this merged and a new update released within the next hour or two. Thanks for your patience!

Hi everyone @dooboolab @hhunaid @408dev @el-lsan @neo125874 @Jarred-Sumner

The new update (3.2.3) has been released and should fix this issue. Please feel free to let me know if you see this issue (or other issues) again and I'll be happy to investigate.

@Nightsd01
I'm using

  "react": "16.3.1",
  "react-native": "0.55.3",
  "react-native-onesignal": "^3.2.3",

on real device everything works fine as expected, but im still receiving null userId randomly on simulators and I don't see any device being added to my player list! ( so far I tested like >50 times and only 2 times worked! )
I tried cleaning and rebuilding the app as well as rm -rf node_modules/ && yarn cache clean && yarn install && yarn start -- --reset-cache but still I dont get the expected status from OneSignal.getPermissionSubscriptionState

{ userSubscriptionEnabled: true,
  subscriptionEnabled: false,
  pushToken: null,
  emailAddress: null,
  userId: null,
  hasPrompted: true,
  notificationsEnabled: true,
  emailUserId: null,
  emailSubscribed: false }

@el-lsan that is expected. It is Apple’s restriction, not ours. iOS simulators cannot receive push notifications. They will not get an APNS push token and won’t get registered with OneSignal.

If you are testing push notifications, you have to do it on a real iOS device, whether you use OneSignal or not.

@Nightsd01
Sorry, my last post was not so clear. I didn't mean receiving the push on simulators but getting the simulator device listed.
So after OneSignal.init('ONESIGNAL_APP_ID'); I'm expecting the simulation device to be listed in my subscribed users with Ios Simulator Unsupported label as you see in following screenshot:

image

Here's the response of OneSignal.getPermissionSubscriptionState for the listed simulator:

image

But most of the times initialization fails on simulators and I don't see it under https://onesignal.com/apps/ONESIGNAL_APP_ID/players

@el-lsan I have same issue push token is null, did you find solution?

@adirzoari after updating to "react-native-onesignal": "^3.2.3" the issue was fixed for real devices, if you meant receving null token for simulator, I believe thats how it's supposed to be.

On the other hand i'm expecting userId to be set for simulators but for some weird reason it fails most of the times and returns null!

Im using real device and get null token

@adirzoari Thats weird! Try clearing the cache rm -rf node_modules/ && yarn cache clean && yarn install && yarn start -- --reset-cache and double check the steps

@el-lsan pushToken is null but in userId has unique string. in onesignal I get
Google Play Services Library Error

I had the same issue with 3.2.7 (simulators - OK/real devices - NOK) but cleaning cache as suggested by @el-lsan got it running with no problem

@Nightsd01 Same here.
Removing init with appId:nil in RCTOneSignal.m helped

hi, would u please the add the image of the following change.

@adirzoari after updating to "react-native-onesignal": "^3.2.3" the issue was fixed for real devices, if you meant receving null token for simulator, I believe thats how it's supposed to be.

On the other hand i'm expecting userId to be set for simulators but for some weird reason it fails most of the times and returns null!

hi i am getting pushToken:null in simulator, and getting only the userId for the simulator.
Would i get the pushToken for the real device, please confirm,(whether, I have to worry about the pushToken null issue in simulator or not ?).

Was this page helpful?
0 / 5 - 0 ratings