3

Our app needs to do integration with IOT devices and we get the NFC driver framework from device manufacturer. But the lib and APIs from the framework is in Swift. I was able to follow this tutorial to invoke bridge at objective-c level, but I have no idea how to invoke the function from Swift. Following is an example of swift integration code from the device manufacturer. Thanks in advance.

import DeviceLib
class NFCViewController: UIViewController {
    private var nfcDriver: NFCDriver?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.nfcDriver = NFCDriver(delegate: self)
    }
    @IBAction func startNFC(_ sender: Any) {
        if self.nfcDriver != nil {
          do {
                try self.nfcDriver!.sessionBegin()
          } catch {}
    }
}
user3453552
  • 199
  • 1
  • 2
  • 11
  • If the provider of the API exposed functions to ObjC, you'd just call them from your bridge. If they didn't, you need to create an objective-C compatible wrapper for all functions from that lib / API you want to access from react-native. A wrapper will be written in Swift, but it will provide access to its functions from ObjC using `@objc`. For example `@objc func startNFC() { ... }`. So react-native will call react-native bridge (objC), which will call your wrapper (Swift, exposed to ObjC), which will call functions of that API/lib (pure Swift). – timbre timbre Feb 05 '22 at 18:22
  • 1
    thanks @thiscommunityistoxic, I did solve the problem by following this tutorial https://teabreak.e-spres-oh.com/swift-in-react-native-the-ultimate-guide-part-1-modules-9bb8d054db03 – user3453552 Feb 06 '22 at 20:41

0 Answers0