React Native Sending Events to JavaScript in Swift

后端 未结 2 463
孤独总比滥情好
孤独总比滥情好 2021-02-06 11:52

How can I send event\'s to JavaScript in Swift?

There is examples of Objc code how to send event to JavaScript, but I need to do in swift?

         


        
2条回答
  •  清酒与你
    2021-02-06 12:42

    It is insane. How to pass anything as an event to Javascript, if this event is generated by Swift?

    I am stuck with the same issue here: "Subclass RCTEventEmitter instead" The following does not work anymore.

    self.bridge.eventDispatcher.sendAppEventWithName( eventName, body: "Woot!" )
    

    I tried:

    var emitter: RCTEventEmitter = RCTEventEmitter()
    

    Instead of:

    var bridge: RCTBridge!
    

    Conesquently:

    self.emitter.sendEvent(withName: eventName, body: "Woot!")
    

    Instead of

    self.bridge.eventDispatcher.sendAppEventWithName( eventName, body: "Woot!" )
    

    From bad to worst, I go from a warning to the following hard error:

    Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error when sending event: Location with body: woot. Bridge is not set. This is probably because you've explicitly synthesized the bridge in RCTEventEmitter, even though it's inherited from RCTEventEmitter.'

    The documentation is very poor and old. It looks that not many people is using this hot garbage. Very frustrating.

    This is an old implementation and it no longer works:

    enter link description here

    Another article, not very useful:

    enter link description here

    Very thorough and complex implementation, no one knows if it still works. In my case it doesn't, I get the same error above:

    enter link description here

    Then there are several objective-c swift cocktails, which I cannot drink at my age:

    enter link description here

提交回复
热议问题