RCTEventEmitter bridge is not set
See original GitHub issueIs 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.30
Then, specify:
- Target Platform: iOS
- Development Operating System:macOS
- Build tools:iOS 10
Steps to Reproduce
- Create a helper class that can emit event from iOS native to JS according to the document.
- invoke sendEventWithName method any where in the code we need to emit event.
Expected Behavior
JS will receive the event and catch the data.
Actual Behavior
[tid:com.facebook.react.ShadowQueue] Exception 'bridge is not set.
This is probably because you've explicitly synthesized the bridge in RCTCameraEvent,
even though it's inherited from RCTEventEmitter.'
was thrown while invoking capture on target CameraManager with params (
{
audio = 0;
barCodeTypes = (
);
description = "";
mirrorImage = 0;
mode = 1;
playSoundOnCapture = 1;
preferredTimeScale = 30;
quality = 0;
target = 1;
title = "";
totalSeconds = 10;
type = 1;
},
3892,
3893
)
Reproducible Demo
EventHelper.h
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
@interface RCTCameraEvent : RCTEventEmitter<RCTBridgeModule>
@end
EventHelper.m
#import "RCTCameraEvent.h"
@implementation RCTCameraEvent
RCT_EXPORT_MODULE();
- (NSArray<NSString *> *)supportedEvents
{
return @[@"CustomEvent"];
}
- (void)sendEvent2JS
{
[self sendEventWithName:@"CustomEvent" body:@{@"name": @"111"}];
}
@end
invoke send event method in code
RCTCameraEvent * cameraEvent = [[RCTCameraEvent alloc]init];
[cameraEvent sendEvent2JS];
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.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Implement RCTEventEmitter in Swift but receive exception for ...
Bridge is not set. This is probably because you've explicitly synthesized the bridge in MyEventEmitter, even though it's inherited from ...
Read more >Emitting (and listening for) events - Building React Native ...
We need to have an empty init constructor; no need to put anything in here. We then create a function registerEmitter to pass...
Read more >RN中OC给JS发消息崩溃报错:bridge is not set. This is ... - 简书
该崩溃报错是由于写法不规范导致的一、官方文档和不合理想法1.官方文档2.不合理想法由于该文档只是点明了calendarEventReminderReceived方法传...
Read more >Implement RCTEventEmitter in Swift but receive exception for ...
Coding example for the question Implement RCTEventEmitter in Swift but receive exception for bridge is not set-swift.
Read more >Native iOS Module in React Native using Swift - YouTube
Learn How to create a Native Module in iOS using swift. Complete Courses: React Native: https://bit.ly/3tDRMTdFlutter: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Finally, I got the solution.
When you use it!
expose an interface like this
‘- (void) socketOpenConnection’
in your “.h” file