Skip to content
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

bridge is not set (bridge always be nil) #15407

Closed
Symous opened this issue Aug 8, 2017 · 5 comments
Closed

bridge is not set (bridge always be nil) #15407

Symous opened this issue Aug 8, 2017 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@Symous
Copy link

Symous commented Aug 8, 2017

I create a iOS class to post event from Native to JS refer to the react native document.

but when I try to execute send event ,it give me an error that

[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
)

we can see that the bridge is nil;

and this is my code :

.h

#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

@interface RCTCameraEvent : RCTEventEmitter<RCTBridgeModule>

@end

.m

#import "RCTCameraEvent.h"

@implementation RCTCameraEvent

RCT_EXPORT_MODULE();

- (NSArray<NSString *> *)supportedEvents
{
    return @[@"RecordVideoStart"];
}

- (void)onRecordVideoStarted
{
    [self sendEventWithName:@"RecordVideoStart" body:@{@"name": @"111"}];
}

@end

code to invoke that :

RCTCameraEvent * cameraEvent = [[RCTCameraEvent alloc]init];
[cameraEvent onRecordVideoStarted];

related issue: #8714

React-Native Version: 0.45.1
Platform : iOS 10

@Symous Symous changed the title bridge is not set bridge is not set (bridge always be nil) Aug 8, 2017
@hramos
Copy link
Contributor

hramos commented Aug 8, 2017

Hey, thanks for reporting this issue!

It looks like your description is missing some necessary information, or the list of reproduction steps is not complete. Can you please add all the details specified in the template? This is necessary for people to be able to understand and reproduce the issue being reported.

I am going to close this, but feel free to open a new issue with the additional information provided. Thanks!

@hramos hramos closed this as completed Aug 8, 2017
@Liqiankun
Copy link

Finally, I got the solution.

#import "RNNotification.h"
@implementation RNNotification

RCT_EXPORT_MODULE();

+ (id)allocWithZone:(NSZone *)zone {
    static RNNotification *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [super allocWithZone:zone];
    });
    return sharedInstance;
}

- (NSArray<NSString *> *)supportedEvents
{
    return @[@"EventReminder"];
}

- (void)sendNotificationToReactNative
{
    [self sendEventWithName:@"EventReminder" body:@{@"name": @"name"}];
}

When you use it!

RNNotification *notification = [RNNotification allocWithZone: nil];
[notification sendNotificationToReactNative]

@ZiBo1233
Copy link

@Liqiankun your demo is working.but i want to know why dose it work?

@Liqiankun
Copy link

@ZiBo1233 Truth be told! I don't know!

@ZiBo1233
Copy link

ZiBo1233 commented Jan 16, 2018

@Liqiankun It's just my guess:In your demo, you create a singleton.The Object is the only one.So the class's bridge becomes the singleton.So,no matter where or when you use it , the bridge object is the same .so ,it works.
I'm not sure the guess is truth or not. 😂

@facebook facebook locked as resolved and limited conversation to collaborators Aug 8, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Aug 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants