6.6 C
New York
Thursday, November 14, 2024

ios – Bridging Swift Delegate for React Native


I’m making an attempt to create assist for React Native for my Swift SDK implementation.

My SDK’s .initialise() technique has a delegate parameter for achievement and failure.
Although I made certain to transform all my public courses and fashions to @objc for compatibility, React native does not have a delegate logic so I’m fighting alternate options.

1st Possibility: Altering logic to callbacks and for the instances that must run async, depend on NSNotifications? Unsure about this method.

@objc(MySDKBridge)
class MySDKBridge: NSObject {
    @objc func initialise() {
    let myDelegate = InitialiseDelegate()
    MySDK.shared.initialise(delegate: myDelegate)
  }
}

extension MySDKBridge: InitialiseDelegate {
func sendEventToReactNative(identify: String, physique: [String: Any]) {
    if let bridge = self.bridge {
        bridge.eventDispatcher().sendAppEvent(withName: identify, physique: physique)
    }
}

func initialiseCompleted() {
    sendEventToReactNative(identify: "InitialisationCompleted", physique: ["status": "success"])
}

func initialiseFailed(message: String) {
    sendEventToReactNative(identify: "InitialisationFailed", physique: ["status": "failure", "message": message])
}
}

2nd Possibility: Change logic to callbacks as an alternative (which I feel React will assist) and possibly depend on NSNotifications and despatched comparable occasions like above for these async instances?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles