Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-Chen committed Apr 4, 2024
2 parents 84fe14b + 868c3f3 commit 14a95bb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
35 changes: 30 additions & 5 deletions ios/Classes/SwiftFlutterNfcKitPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public class SwiftFlutterNfcKitPlugin: NSObject, FlutterPlugin, NFCTagReaderSess
} else {
result("not_supported")
}
} else if call.method == "restartPolling" {
if let session = session {
self.result = result
session.restartPolling()
} else {
result(FlutterError(code: "404", message: "No active session", details: nil))
}
} else if call.method == "poll" {
if session != nil {
result(FlutterError(code: "406", message: "Cannot invoke poll in a active session", details: nil))
Expand Down Expand Up @@ -508,8 +515,8 @@ public class SwiftFlutterNfcKitPlugin: NSObject, FlutterPlugin, NFCTagReaderSess
case let .feliCa(tag):
result["type"] = "iso18092"
result["standard"] = "ISO 18092 (FeliCa)"
result["id"] = tag.currentIDm.hexEncodedString()
result["systemCode"] = tag.currentSystemCode.hexEncodedString()
result["manufacturer"] = tag.currentIDm.hexEncodedString()
case let .iso15693(tag):
result["type"] = "iso15693"
result["standard"] = "ISO 15693"
Expand All @@ -518,6 +525,7 @@ public class SwiftFlutterNfcKitPlugin: NSObject, FlutterPlugin, NFCTagReaderSess
default:
result["type"] = "unknown"
result["standard"] = "unknown"
result["id"] = "unknown"
}

session.connect(to: firstTag) { (error: Error?) in
Expand Down Expand Up @@ -555,10 +563,27 @@ public class SwiftFlutterNfcKitPlugin: NSObject, FlutterPlugin, NFCTagReaderSess
result["ndefCapacity"] = capacity
}
// ignore error, just return with ndef disabled
let jsonData = try! JSONSerialization.data(withJSONObject: result)
let jsonString = String(data: jsonData, encoding: .utf8)
self.result?(jsonString)
self.result = nil
switch self.tag {
case let .feliCa(tag):
tag.polling(systemCode: tag.currentSystemCode, requestCode: .noRequest, timeSlot: .max16) { (pmm: Data, _: Data, error: Error?) in
if let error = error {
self.result?(FlutterError(code: "500", message: "Communication error on connect", details: error.localizedDescription))
self.result = nil
} else {
result["manufacturer"] = pmm.hexEncodedString()

let jsonData = try! JSONSerialization.data(withJSONObject: result)
let jsonString = String(data: jsonData, encoding: .utf8)
self.result?(jsonString)
self.result = nil
}
}
default:
let jsonData = try! JSONSerialization.data(withJSONObject: result)
let jsonString = String(data: jsonData, encoding: .utf8)
self.result?(jsonString)
self.result = nil
}
}
} else {
let jsonData = try! JSONSerialization.data(withJSONObject: result)
Expand Down
9 changes: 8 additions & 1 deletion lib/flutter_nfc_kit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NFCTag {
/// The standard that the tag complies with (can be `unknown`)
final String standard;

/// Tag ID
/// Tag ID (can be `unknown`)
final String id;

/// ATQA (Type A only, Android only)
Expand Down Expand Up @@ -343,6 +343,13 @@ class FlutterNfcKit {
return NFCTag.fromJson(jsonDecode(data));
}

/// Works only on iOS
/// Calls NFCTagReaderSession.restartPolling()
/// Call this if you have received "Tag connection lost" exception
/// This will allow to reconnect to tag without closing system popup
static Future<void> iosRestartPolling() async =>
await _channel.invokeMethod("restartPolling");

/// Transceive data with the card / tag in the format of APDU (iso7816) or raw commands (other technologies).
/// The [capdu] can be either of type Uint8List or hex string.
/// Return value will be in the same type of [capdu].
Expand Down

0 comments on commit 14a95bb

Please sign in to comment.