-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
RCTEventEmitter bridge is not set #15421
Comments
You shouldn't init |
I agree this is a bit tricky and some help from the framework and documentation would be nice |
This is also a very nice way. https://gist.github.com/brennanMKE/1ebba84a0fd7c2e8b481e4f8a5349b99 I think this is exactly what you are looking for? |
Finally, I got the solution.
When you use it!
|
Yep, singleton pattern is one option. |
you save my day @Liqiankun |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
@Liqiankun I did the same thing as you, still getting a damn error in my AppDelegate These are my files:
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
@interface RTNEventManager : RCTEventEmitter <RCTBridgeModule>
@end
#import "RTNEventManager.h"
@implementation RTNEventManager
RCT_EXPORT_MODULE();
+ (id)allocWithZone:(NSZone *)zone {
static RTNEventManager *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [super allocWithZone:zone];
});
return sharedInstance;
}
- (NSArray<NSString *> *)supportedEvents
{
return @[@"onOpened"];
}
- (void)socketOpenConnection
{
[self sendEventWithName:@"onOpened" body:@{@"callername": @"205-966-1916", @"username": @"9542493959"}];
}
@end and then inside my AppDelegate.m I do this #import "RTNEventManager.h"
...
RTNEventManager *manager = [RTNEventManager allocWithZone: nil];
[manager socketOpenConnection]; And when building it pops up the same error again and again. |
expose an interface like this '- (void) socketOpenConnection' in your ".h" file |
Is this a bug report?
Not confirm.
Have you read the Contributing Guidelines?
Yes, I have follow all sept of this document of how to use RCTEventEmitter to send event from Native to JS.but still meet this error.
Environment
react-native -v
: 0.45.1node -v
: 8.1.2npm -v
: 5.30Then, specify:
Steps to Reproduce
Expected Behavior
JS will receive the event and catch the data.
Actual Behavior
Reproducible Demo
EventHelper.h
EventHelper.m
invoke send event method in code
All I want to do is create a helper class so that I can invoke the send event method anywhere I need.
I have look into many issues (#8714) and search related answer on Google and stackoverflow but still can not found a perfect solution using RCTEventEmitter. there are lots of developers like me meet this problem and react native haven't provide us a standard code demo or completely document.
The text was updated successfully, but these errors were encountered: