NFCScanning.mdkproject/
┣ App_Resources/
┃ ┣ Android/
┃ ┃ ┗ src/
┃ ┃ ┗ main/
┃ ┗ iOS/
┃ ┣ src/
┃ ┃ ┗ NFCScanningControllerBridge.swift
┃ ┗ app.entitlements
┣ App_Resources_Merge/
┃ ┗ iOS/
┃ ┗ Info.plist
┣ extensions/
┣ BrandedSettings.json
┗ MDKProject.json
import UIKit
import CoreNFC
@objc(NFCScanningControlBridge)
public class NFCScanningControlBridge: NSObject, NFCTagReaderSessionDelegate {
var session: NFCTagReaderSession?
@objc public var onNFCFoundCallback: ((String) -> Void)? = nil
public override init() {
super.init()
CaptureNFC()
}
@objc public func CaptureNFC() {
print("CaptureNFC");
self.session = NFCTagReaderSession(pollingOption: .iso14443, delegate: self)
self.session?.alertMessage = "Hold Your Phone Near the NFC Tag"
self.session?.begin()
}
public func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) {
print("Session Begun!")
}
public func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) {
print("Error with Launching Session")
}
public func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
if tags.count > 1{
session.alertMessage = "More Than One Tag Detected, Please try again"
session.invalidate()
}
let tag = tags.first!
session.connect(to: tag) { (error) in
if nil != error{
session.invalidate(errorMessage: "Connection Failed")
}
if case let .miFare(sTag) = tag{
let UID = sTag.identifier.map{ String(format: "%.2hhx", $0)}.joined()
print("UID:", UID)
print(sTag.identifier)
session.invalidate()
// Use main thread
DispatchQueue.main.async {
self.onNFCFoundCallback?(UID);
}
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>NDEF</string>
<string>TAG</string>
</array>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NFCReaderUsageDescription</key>
<string>core</string>
</dict>
</plist>
/**
* Describe this function...
* @param {IClientAPI} clientAPI
*/
export default function Scan(clientAPI) {
try {
// Create instance native iOS nfc scanning class
var _iOSNFCScanControl = NFCScanningControlBridge.new();
// Callback function with nfc tag uid
_iOSNFCScanControl.onNFCFoundCallback = (tagUID) => {
alert("Tag found: " + tagUID );
}
} catch (err) {
alert("errer" + err)
};
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
10 | |
9 | |
7 | |
4 | |
4 | |
3 | |
3 | |
2 | |
2 |