React-native-onesignal: An error is shown when running init from iOS - RNOneSignal.initWithAppId undefined is not an object

Created on 11 May 2018  ·  31Comments  ·  Source: OneSignal/react-native-onesignal

Description:
An error is shown when running init from iOS, Android is good

TypeError: TypeError: undefined is not an object (evaluating 'RNOneSignal.initWithAppId')

Environment

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

Steps to Reproduce Issue:

  1. After install guide (with js init)
  2. Run init from js

Most helpful comment

Hi Guys, I solve this problem. You just need cd ios then run pod install, then you need to add in your project libraries RCTOneSigna from node_modules, then add in Build Settings --> Header Search Paths $(SRCROOT)/../node_modules/react-native-onesignal/ios/RCTOneSignal and $(SRCROOT)/../node_modules/react-native-onesignal/ios recursive both.

All 31 comments

+1, i have same problem

"react-native-onesignal": "^3.2.1",

i call OneSignal.init('appId')

+1 "react-native-onesignal": "^3.2.1"

+1 Just tried this functionality as well on 3.2.1, except OneSignal seemingly does nothing on .init(). My device never shows up in the OneSignal console. May be tied to this issue, especially if the library is silently failing on my end for some reason.

@dorshay6 @mnshkv @podvipodvert

Are any of you trying to run in Expo? We recently updated the SDK so that it would silently do nothing (not crash, not function, etc) in the Expo client. It will basically stay uninitialized until you detach from Expo and run it natively.

However it looks like we didn't add this check to the init() function so if you call it from the Expo client it will crash, we'll be fixing this soon.

In any case, this indicates that the RNOneSignal native event emitter isn't getting initialized somehow. The only environment I know that would cause this would be Expo

Not in expo, might be a bad install? cant find where I'm wrong

It could be a linking issue. Are you sure you ran react-native link react-native-onesignal?

Can you import RCTOneSignal.h in the AppDelegate and use the native method to initialize? The old native initialization method is deprecated but it still works.

I did run the link but it didn't help, will try to import later

same problem "react-native": "0.50.4", "react-native-onesignal": "^3.2.1",

Hi Guys, I solve this problem. You just need cd ios then run pod install, then you need to add in your project libraries RCTOneSigna from node_modules, then add in Build Settings --> Header Search Paths $(SRCROOT)/../node_modules/react-native-onesignal/ios/RCTOneSignal and $(SRCROOT)/../node_modules/react-native-onesignal/ios recursive both.

@podvipodvert Do you have the next line in your podfile pod 'react-native-onesignal', :path => '../node_modules/react-native-onesignal' ?

@dorshay6 yes

@Nightsd01 Can you please share the the docs for native init in iOS? cant find them in this repo

@podvipodvert can you please tell me more about this step then you need to add in your project libraries RCTOneSigna from node_modules ? I did both pod install and added search paths but still no solution for me

@dorshay6 open your node_modules folder, find react native onesignal then ios folder, then just drag them =) like this

Hey guys, after running react-native link react-native-onesignal can you verify that in the Xcode project, libRCTOneSignal.a shows up in the Linked Libraries section of the project settings in xcode?

@dorshay6 Version 3.2.2 fixes our Podspec that would have caused compiler issues with cocoapods. But really you shouldn't need to use cocoapods unless all of your other dependencies are installed with it. Otherwise just use npm and react linking.

To anyone who is still having this issue, please do one of two things:

  1. If you ARE using cocoapods to install iOS dependencies (ie. React dependencies), please update to react-native-onesignal 3.2.2 and run pod install

  2. If you are NOT using cocoapods to install iOS dependencies, you will need to make sure react-native-onesignal shows up as an Xcode subproject like in this screenshot. If you don't see RCTOneSignal as an Xcode project, please let me know

Was anyone able to make this work? I just had the 3.2.2 version and I made it work on Android by adding the configure() method with an empty object as parameter just before the init() but in iOS, it still won't work. @Nightsd01 I have exactly the screenshot you provided on my Xcode project but still no luck. Please help. Thanks.

@dorshay6 Please let me know if 3.2.3 resolves this issue for you

Just fixed this on my end. After installing 3.2.3 I had to remove libRCTOneSignal.a from the Linked Libraries section and then re-add it. Now calling OneSignal.init() works a charm :).

That sounds like an Xcode pbxproject linking issue - it happens. Usually you can literally just replace the static library (like libOneSignal.a) and Xcode will be able to link to it just fine.

I'm closing this issue because it should be fixed by 3.2.3 - please feel free to respond if you are still encountering this problem and I'll be happy to reopen the issue & investigate!

@Nightsd01 Solved for me thanks

+1 i had same problem.
i used react-native link react-native-onesignal again and resolved my problem.

screen shot 2018-05-21 at 1 43 02 pm

I have solved it by linking library manually.

@Nightsd01, I need some help.
I'm using react-native-onesignal: 3.2.5, but after install & link the lib didn't shows up as an Xcode subproject.
How can i add it manually?

@matias91 have a look at this portion of the doc.
https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking

@matias91 yeah, @shafayeatsumit's link is what you should do. Basically you need to drag the RCTOneSignal.xcodeproj file (from node_modules) into your Xcode project and then link the library in your target's Link Binary with Libraries section

Thanks for the answers, @shafayeatsumit and @Nightsd01.
That did the trick!

Thanks @shafayeatsumit, that did the trick for me! This happened to me when I uninstalled the package because It was messed up due to updating. I installed it again and manually linking it fixed it. 👍

You have to add (libRCTOneSignal.a) to your main application target also.
That solves my problem

add "libRCTOneSignal.a" in main project -> Build Phases -> Link Binary with Libararies

Was this page helpful?
0 / 5 - 0 ratings