Reputation: 539
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.
Upvotes: 1
Views: 3049
Reputation: 1382
You can also just add a plain RCT_EXPORT();
to any method you want to export. Works like a charm.
Upvotes: 0
Reputation: 16466
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
Upvotes: 2