radarlabs / react-native-radar

React Native module for Radar, the leading geofencing and location tracking platform
https://radar.com
Apache License 2.0
170 stars 32 forks source link

NativeModules.RNRadar is undefined #51

Closed phil-andrews closed 5 years ago

phil-andrews commented 5 years ago

Describe the bug When running on the iOS emulator any Radar function produces a "NativeModules.RNRadar is undefined" error. I have followed the SDK instructions for iOS. I have not installed for Android.

The app, which is just the basic rn template app, runs fine until I call Radar.

To Reproduce Steps to reproduce the behavior:

  1. Start clean project using rn typescript template.
  2. Follow SDK installation instructions from Radar docs.
  3. Install RN package and follow installation instructions.
  4. Call Radar from App.tsx in componentDidMount.

Expected behavior Radar functions to be available.

Screenshots

screen shot 2018-12-16 at 9 30 55 pm screen shot 2018-12-16 at 9 31 37 pm screen shot 2018-12-16 at 9 32 36 pm

Metadata (please complete the following information): "react-native": "0.57.8", "react-native-radar": "^2.1.2" emulator XR xCode 10

Update: In the Plist screenshot you'll see an empty string for one of the privacy settings. I put in a string and it didn't change anything.

The errors in AppDelegate don't have an effect at runtime.

phil-andrews commented 5 years ago

Cross posted this to StackOverflow.

russellcullen commented 5 years ago

Have you installed the native dependencies with react-native link react-native-radar?

Additionally - there looks to be some sort of a configuration problem since the native errors shown above would not compile - the malformed string literal in particular. Would you mind sharing your linked dependencies? (Found in Build Phases -> Link Binary With Libraries)

phil-andrews commented 5 years ago

I have linked with react-native link react-native-radar.

screen shot 2018-12-17 at 6 08 02 pm
russellcullen commented 5 years ago

Mind also expanding that Libraries directory in the left pane there? RNRadar.xcodeproj should be in that list, otherwise there might be an issue with your header search paths.

Your header search paths may need to include $(SRCROOT)/../node_modules/react-native-radar/ios if not already added. Or pointing to wherever your node_modules/react-native-radar/ios module is located.

phil-andrews commented 5 years ago
screen shot 2018-12-17 at 6 36 05 pm

The node_module search paths are there under build settings. That's part of the mystery since we're calling the radar initialization code from AppDelegate. If it couldn't find the module I'd expect it to fail with a "can't find headers" error in iOS during the build. Instead the app builds fine up until I uncomment out Radar.whatever in the RN js.

russellcullen commented 5 years ago

Yeah, this is very odd as that native could shouldn't even compile; the string literal in [Radar initializeWithPublishableKey:"key"] should fail, should be [Radar initializeWithPublishableKey:@"key"]. I've noticed that react native builds can fail but the toolchain still pushes an old version of the .app to the simulator, its worth double checking that your build is succeeding.

However, that issue seems separate since your error is caught in the JS runtime. Normally this would mean the RNRadar ios module isn't being linked and thus registered so no module is found at runtime. In your case, the linking appears to be happening so either the registration (with react native macros) isn't happening or possibly compilation in general (evidenced by the syntax error not being caught).

phil-andrews commented 5 years ago

That was it. Showing my lack of Obj-C chops it was the @. Funny that didn't fail. But alright, we're up and running now.

russellcullen commented 5 years ago

Happy that fixed it! Sorry about the confusion, the error messages from React Native sometimes are way off 😝

phil-andrews commented 5 years ago

No worries, thanks for the help!