1

I am following this guide http://facebook.github.io/react-native/docs/nativemodulesios.html#content

And also this website: http://colinramsay.co.uk/2015/03/27/react-native-simple-native-module.html

But does not matter where i add the .h and .m files i always get the error: Class ClassName was not exported Did you forget to use RTC_EXPORT_MODULE()?

Even if it the same code from the examples from react-native documentation, can anyone guide me where to add the .h and .m files and properly link them to the project? Thanks.

2 Answers 2

2

There has been a change in the native module API and it seems the docs haven't been updated accordingly. From the example in my article, SomeString.m should look like this:

//  SomeString.m
#import "SomeString.h"

@implementation SomeString

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(get:(RCTResponseSenderBlock)callback)
{ 
  // Change this depending on what you want to retrieve:
  NSString* someString = @"something";

  callback(@[someString]);
}

@end

This ends up with the desired result and you can call it from JS in the same way as before. It looks like this only just happened:

https://github.com/facebook/react-native/commit/0686b0147c8c8084e4a226b7ea04585362eccea8

Sign up to request clarification or add additional context in comments.

1 Comment

Awsome, it was just that, i changed that and everything started working. Instant fan now!
0

You can also just add a plain RCT_EXPORT(); to any method you want to export. Works like a charm.

1 Comment

This approach is deprecated and has now been removed. It was slightly more convenient to use, but wasn't as good as the new system because we couldn't do proper type validation on the method arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.