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

(v3.2.1) (iOS) pushToken null on real device #503

Closed
tavriaforever opened this issue May 14, 2018 · 36 comments
Closed

(v3.2.1) (iOS) pushToken null on real device #503

tavriaforever opened this issue May 14, 2018 · 36 comments

Comments

@tavriaforever
Copy link

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
@tavriaforever
Copy link
Author

I found the same problem #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

@Nightsd01
Copy link
Contributor

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

@Jarred-Sumner
Copy link

Jarred-Sumner commented May 14, 2018

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)

@Nightsd01
Copy link
Contributor

Nightsd01 commented May 14, 2018

@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
Copy link

@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

@Nightsd01
Copy link
Contributor

Nightsd01 commented May 14, 2018

@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?

@hhunaid
Copy link

hhunaid commented May 15, 2018

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

@Nightsd01
Copy link
Contributor

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

@hhunaid
Copy link

hhunaid commented May 15, 2018

@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.

@Nightsd01
Copy link
Contributor

@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?

@hhunaid
Copy link

hhunaid commented May 15, 2018

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.

@hyochan
Copy link

hyochan commented May 15, 2018

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"

@Nightsd01
Copy link
Contributor

@dooboolab You are using JS initialization, correct?

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

@Nightsd01
Copy link
Contributor

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.

@neo125874
Copy link

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

@el-lsan
Copy link

el-lsan commented May 16, 2018

same issue here, any solution ?

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

@hyochan
Copy link

hyochan commented May 16, 2018

@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.

@408dev
Copy link

408dev commented May 16, 2018

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

@hyochan
Copy link

hyochan commented May 16, 2018

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

@hhunaid
Copy link

hhunaid commented May 16, 2018

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.

@hyochan
Copy link

hyochan commented May 16, 2018

@hhunaid sounds like I should downgrade?

@Nightsd01
Copy link
Contributor

@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.

@Nightsd01
Copy link
Contributor

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.

@Nightsd01
Copy link
Contributor

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!

@Nightsd01
Copy link
Contributor

Nightsd01 commented May 17, 2018

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.

@el-lsan
Copy link

el-lsan commented May 17, 2018

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

@Nightsd01
Copy link
Contributor

@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.

@el-lsan
Copy link

el-lsan commented May 18, 2018

@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

@adirzoari
Copy link

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

@el-lsan
Copy link

el-lsan commented May 20, 2018

@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!

@adirzoari
Copy link

Im using real device and get null token

@el-lsan
Copy link

el-lsan commented May 21, 2018

@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

@adirzoari
Copy link

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

@marcoj
Copy link

marcoj commented Sep 18, 2018

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

@CVRamana
Copy link

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

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

@CVRamana
Copy link

CVRamana commented May 27, 2020

@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 ?).

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

No branches or pull requests