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

Problem sending a request from Obj-C #49

Open
jduthon opened this issue Dec 28, 2018 · 0 comments
Open

Problem sending a request from Obj-C #49

jduthon opened this issue Dec 28, 2018 · 0 comments

Comments

@jduthon
Copy link

jduthon commented Dec 28, 2018

I have a problem trying to send a request and I get the following error message:

Bridge is not set. This is probably because you've explicitly synthesized the bridge in ElectrodeBridgeTransceiver, even though it's inherited from RCTEventEmitter.

I am trying to use the ElectrodeRequestProcessor from a Swift file, imported in my AppDelegate.m inside of the ErnRunner.xcodeproj of my electrode-native project.
Somehow registering to an event coming from JS works well, but then when I am trying to send an event I run into the above mentioned error.

The relevant Swift code:

    @objc public static func sendRequest(payload: String) {
        let requestProcessor = ElectrodeRequestProcessor<String, String, String>(
            requestName: "communication.native",
            requestPayload: payload,
            respClass: String.self,
            responseItemType: String.self,
            responseCompletionHandler: { responseMessage, failureMessage in
                if let failure = failureMessage {
                    print("Request to JS failed \(failure.message)")
                } else {
                    if let responseMessageString = responseMessage as? String {
                        print("Request response from JS \(responseMessageString)")
                    }
                }
        }
        )
        requestProcessor.execute()
    }

The relevant obj-c code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Start the container
    ElectrodeContainerConfig *containerConfig = [[ElectrodeContainerConfig alloc] init];
    containerConfig.debugEnabled = RnDevSupportEnabled;
    [ElectrodeReactNative startWithConfigurations:containerConfig];
    [RequestHandler startListener];
    [RequestHandler sendRequestWithPayload:@"from native"];
    return YES;
}

Somehow in the real project (importing the miniapp) the same code works well, though I can see 2 main differences:

  • The code is Swift
  • The call to the request is made later

To try to deny/confirm the latest, I added some delay (30s) before trying to send the request, but I get the same error.

If you have any ideas on how to troubleshoot and fix I would be glad, and hope I did not write too much non-sense, I am really new to iOS development.

@jduthon jduthon changed the title Problem sending a request Problem sending a request from Obj-C Dec 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant