@exxili/capacitor-nfc 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ExxiliCapacitorNfc.podspec +17 -17
- package/Package.swift +28 -28
- package/README.md +597 -595
- package/android/build.gradle +67 -67
- package/android/src/main/AndroidManifest.xml +2 -2
- package/android/src/main/kotlin/com/exxili/capacitornfc/MainActivity.kt +11 -11
- package/android/src/main/kotlin/com/exxili/capacitornfc/NFCPlugin.kt +492 -464
- package/dist/esm/definitions.d.ts +13 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +4 -1
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +4 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +4 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/NFCPlugin/NFCPlugin.swift +181 -169
- package/ios/Sources/NFCPlugin/NFCReader.swift +507 -507
- package/ios/Sources/NFCPlugin/NFCWriter.swift +89 -89
- package/ios/Tests/NFCPluginTests/NFCPluginTests.swift +15 -15
- package/package.json +90 -90
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import CoreNFC
|
|
3
|
-
|
|
4
|
-
@objc public class NFCWriter: NSObject, NFCNDEFReaderSessionDelegate {
|
|
5
|
-
private var writerSession: NFCNDEFReaderSession?
|
|
6
|
-
private var messageToWrite: NFCNDEFMessage?
|
|
7
|
-
|
|
8
|
-
public var onWriteSuccess: (() -> Void)?
|
|
9
|
-
public var onError: ((Error) -> Void)?
|
|
10
|
-
|
|
11
|
-
@objc public func startWriting(message: NFCNDEFMessage) {
|
|
12
|
-
print("NFCWriter startWriting called")
|
|
13
|
-
self.messageToWrite = message
|
|
14
|
-
|
|
15
|
-
guard NFCNDEFReaderSession.readingAvailable else {
|
|
16
|
-
print("NFC writing not supported on this device")
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
writerSession = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false)
|
|
20
|
-
writerSession?.alertMessage = "Hold your iPhone near the NFC tag to write."
|
|
21
|
-
writerSession?.begin()
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// NFCNDEFReaderSessionDelegate methods for writing
|
|
28
|
-
public func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
|
|
29
|
-
print("NFC writer session error: \(error.localizedDescription)")
|
|
30
|
-
onError?(error)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public func readerSessionDidBecomeActive(_ session: NFCNDEFReaderSession) {
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public func readerSession(_ session: NFCNDEFReaderSession, didDetect tags: [NFCNDEFTag]) {
|
|
38
|
-
if tags.count > 1 {
|
|
39
|
-
let retryInterval = DispatchTimeInterval.milliseconds(500)
|
|
40
|
-
session.alertMessage = "More than one tag detected. Please try again."
|
|
41
|
-
DispatchQueue.global().asyncAfter(deadline: .now() + retryInterval) {
|
|
42
|
-
session.restartPolling()
|
|
43
|
-
}
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
guard let tag = tags.first else { return }
|
|
48
|
-
|
|
49
|
-
session.connect(to: tag) { (error) in
|
|
50
|
-
if let error = error {
|
|
51
|
-
session.invalidate(errorMessage: "Unable to connect to tag.")
|
|
52
|
-
self.onError?(error)
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
tag.queryNDEFStatus { (ndefStatus, _, error) in
|
|
57
|
-
if let error = error {
|
|
58
|
-
session.invalidate(errorMessage: "Unable to query the NDEF status of tag.")
|
|
59
|
-
self.onError?(error)
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
switch ndefStatus {
|
|
64
|
-
case .notSupported:
|
|
65
|
-
session.invalidate(errorMessage: "Tag is not NDEF compliant.")
|
|
66
|
-
case .readOnly:
|
|
67
|
-
session.invalidate(errorMessage: "Tag is read-only.")
|
|
68
|
-
case .readWrite:
|
|
69
|
-
if let message = self.messageToWrite {
|
|
70
|
-
tag.writeNDEF(message) { (error) in
|
|
71
|
-
if let error = error {
|
|
72
|
-
session.invalidate(errorMessage: "Failed to write NDEF message.")
|
|
73
|
-
self.onError?(error)
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
session.alertMessage = "NDEF message written successfully."
|
|
77
|
-
session.invalidate()
|
|
78
|
-
self.onWriteSuccess?()
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
session.invalidate(errorMessage: "No message to write.")
|
|
82
|
-
}
|
|
83
|
-
@unknown default:
|
|
84
|
-
session.invalidate(errorMessage: "Unknown NDEF tag status.")
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
import Foundation
|
|
2
|
+
import CoreNFC
|
|
3
|
+
|
|
4
|
+
@objc public class NFCWriter: NSObject, NFCNDEFReaderSessionDelegate {
|
|
5
|
+
private var writerSession: NFCNDEFReaderSession?
|
|
6
|
+
private var messageToWrite: NFCNDEFMessage?
|
|
7
|
+
|
|
8
|
+
public var onWriteSuccess: (() -> Void)?
|
|
9
|
+
public var onError: ((Error) -> Void)?
|
|
10
|
+
|
|
11
|
+
@objc public func startWriting(message: NFCNDEFMessage) {
|
|
12
|
+
print("NFCWriter startWriting called")
|
|
13
|
+
self.messageToWrite = message
|
|
14
|
+
|
|
15
|
+
guard NFCNDEFReaderSession.readingAvailable else {
|
|
16
|
+
print("NFC writing not supported on this device")
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
writerSession = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false)
|
|
20
|
+
writerSession?.alertMessage = "Hold your iPhone near the NFC tag to write."
|
|
21
|
+
writerSession?.begin()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// NFCNDEFReaderSessionDelegate methods for writing
|
|
28
|
+
public func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
|
|
29
|
+
print("NFC writer session error: \(error.localizedDescription)")
|
|
30
|
+
onError?(error)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public func readerSessionDidBecomeActive(_ session: NFCNDEFReaderSession) {
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public func readerSession(_ session: NFCNDEFReaderSession, didDetect tags: [NFCNDEFTag]) {
|
|
38
|
+
if tags.count > 1 {
|
|
39
|
+
let retryInterval = DispatchTimeInterval.milliseconds(500)
|
|
40
|
+
session.alertMessage = "More than one tag detected. Please try again."
|
|
41
|
+
DispatchQueue.global().asyncAfter(deadline: .now() + retryInterval) {
|
|
42
|
+
session.restartPolling()
|
|
43
|
+
}
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
guard let tag = tags.first else { return }
|
|
48
|
+
|
|
49
|
+
session.connect(to: tag) { (error) in
|
|
50
|
+
if let error = error {
|
|
51
|
+
session.invalidate(errorMessage: "Unable to connect to tag.")
|
|
52
|
+
self.onError?(error)
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
tag.queryNDEFStatus { (ndefStatus, _, error) in
|
|
57
|
+
if let error = error {
|
|
58
|
+
session.invalidate(errorMessage: "Unable to query the NDEF status of tag.")
|
|
59
|
+
self.onError?(error)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
switch ndefStatus {
|
|
64
|
+
case .notSupported:
|
|
65
|
+
session.invalidate(errorMessage: "Tag is not NDEF compliant.")
|
|
66
|
+
case .readOnly:
|
|
67
|
+
session.invalidate(errorMessage: "Tag is read-only.")
|
|
68
|
+
case .readWrite:
|
|
69
|
+
if let message = self.messageToWrite {
|
|
70
|
+
tag.writeNDEF(message) { (error) in
|
|
71
|
+
if let error = error {
|
|
72
|
+
session.invalidate(errorMessage: "Failed to write NDEF message.")
|
|
73
|
+
self.onError?(error)
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
session.alertMessage = "NDEF message written successfully."
|
|
77
|
+
session.invalidate()
|
|
78
|
+
self.onWriteSuccess?()
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
session.invalidate(errorMessage: "No message to write.")
|
|
82
|
+
}
|
|
83
|
+
@unknown default:
|
|
84
|
+
session.invalidate(errorMessage: "Unknown NDEF tag status.")
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import XCTest
|
|
2
|
-
@testable import NFCPlugin
|
|
3
|
-
|
|
4
|
-
class NFCTests: XCTestCase {
|
|
5
|
-
func testEcho() {
|
|
6
|
-
// This is an example of a functional test case for a plugin.
|
|
7
|
-
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
-
|
|
9
|
-
let implementation = NFC()
|
|
10
|
-
let value = "Hello, World!"
|
|
11
|
-
let result = implementation.echo(value)
|
|
12
|
-
|
|
13
|
-
XCTAssertEqual(value, result)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import NFCPlugin
|
|
3
|
+
|
|
4
|
+
class NFCTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = NFC()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@exxili/capacitor-nfc",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A Capacitor plugin for reading and writing NFC NDEFtags.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/plugin.cjs.js",
|
|
7
|
-
"module": "dist/esm/index.js",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./dist/esm/index.js",
|
|
11
|
-
"require": "./dist/plugin.cjs.js",
|
|
12
|
-
"types": "./dist/esm/index.d.ts"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"types": "dist/esm/index.d.ts",
|
|
16
|
-
"unpkg": "dist/plugin.js",
|
|
17
|
-
"files": [
|
|
18
|
-
"android/src/main/",
|
|
19
|
-
"android/build.gradle",
|
|
20
|
-
"dist/",
|
|
21
|
-
"ios/Sources",
|
|
22
|
-
"ios/Tests",
|
|
23
|
-
"Package.swift",
|
|
24
|
-
"ExxiliCapacitorNfc.podspec"
|
|
25
|
-
],
|
|
26
|
-
"author": "Exxili",
|
|
27
|
-
"license": "MIT",
|
|
28
|
-
"repository": {
|
|
29
|
-
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/Exxili/capacitor-nfc.git"
|
|
31
|
-
},
|
|
32
|
-
"bugs": {
|
|
33
|
-
"url": "https://github.com/Exxili/capacitor-nfc/issues"
|
|
34
|
-
},
|
|
35
|
-
"keywords": [
|
|
36
|
-
"capacitor",
|
|
37
|
-
"plugin",
|
|
38
|
-
"native"
|
|
39
|
-
],
|
|
40
|
-
"scripts": {
|
|
41
|
-
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
42
|
-
"verify:ios": "xcodebuild -scheme CapacitorNfc -destination generic/platform=iOS",
|
|
43
|
-
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
44
|
-
"verify:web": "npm run build",
|
|
45
|
-
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
46
|
-
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
47
|
-
"eslint": "eslint . --ext ts",
|
|
48
|
-
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
49
|
-
"swiftlint": "node-swiftlint lint ios/Sources/NFCPlugin --config .swiftlint.yml",
|
|
50
|
-
"docgen": "docgen --api NFCPlugin --output-readme README.md --output-json dist/docs.json",
|
|
51
|
-
"build": "npm run clean && tsc && rollup -c rollup.config.js && rimraf *.tgz && npm pack",
|
|
52
|
-
"clean": "rimraf ./dist",
|
|
53
|
-
"watch": "tsc --watch",
|
|
54
|
-
"prepublishOnly": "npm run build"
|
|
55
|
-
},
|
|
56
|
-
"devDependencies": {
|
|
57
|
-
"@capacitor/android": "^6.0.0",
|
|
58
|
-
"@capacitor/core": "^6.0.0",
|
|
59
|
-
"@capacitor/docgen": "^0.2.2",
|
|
60
|
-
"@capacitor/ios": "^6.0.0",
|
|
61
|
-
"@ionic/eslint-config": "^0.4.0",
|
|
62
|
-
"@ionic/prettier-config": "^4.0.0",
|
|
63
|
-
"@ionic/swiftlint-config": "^1.1.2",
|
|
64
|
-
"@types/node": "^22.18.8",
|
|
65
|
-
"eslint": "^8.57.0",
|
|
66
|
-
"prettier": "^3.3.3",
|
|
67
|
-
"prettier-plugin-java": "^2.6.4",
|
|
68
|
-
"rimraf": "^3.0.2",
|
|
69
|
-
"rollup": "^2.32.0",
|
|
70
|
-
"swiftlint": "^1.0.1",
|
|
71
|
-
"typescript": "^5.9.3"
|
|
72
|
-
},
|
|
73
|
-
"peerDependencies": {
|
|
74
|
-
"@capacitor/core": ">=6.0.0 <9.0.0"
|
|
75
|
-
},
|
|
76
|
-
"prettier": "@ionic/prettier-config",
|
|
77
|
-
"swiftlint": "@ionic/swiftlint-config",
|
|
78
|
-
"eslintConfig": {
|
|
79
|
-
"extends": "@ionic/eslint-config/recommended"
|
|
80
|
-
},
|
|
81
|
-
"capacitor": {
|
|
82
|
-
"ios": {
|
|
83
|
-
"src": "ios",
|
|
84
|
-
"podspec": "ExxiliCapacitorNfc.podspec"
|
|
85
|
-
},
|
|
86
|
-
"android": {
|
|
87
|
-
"src": "android"
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@exxili/capacitor-nfc",
|
|
3
|
+
"version": "0.0.14",
|
|
4
|
+
"description": "A Capacitor plugin for reading and writing NFC NDEFtags.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/plugin.cjs.js",
|
|
7
|
+
"module": "dist/esm/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"require": "./dist/plugin.cjs.js",
|
|
12
|
+
"types": "./dist/esm/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"types": "dist/esm/index.d.ts",
|
|
16
|
+
"unpkg": "dist/plugin.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"android/src/main/",
|
|
19
|
+
"android/build.gradle",
|
|
20
|
+
"dist/",
|
|
21
|
+
"ios/Sources",
|
|
22
|
+
"ios/Tests",
|
|
23
|
+
"Package.swift",
|
|
24
|
+
"ExxiliCapacitorNfc.podspec"
|
|
25
|
+
],
|
|
26
|
+
"author": "Exxili",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/Exxili/capacitor-nfc.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/Exxili/capacitor-nfc/issues"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"capacitor",
|
|
37
|
+
"plugin",
|
|
38
|
+
"native"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
42
|
+
"verify:ios": "xcodebuild -scheme CapacitorNfc -destination generic/platform=iOS",
|
|
43
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
44
|
+
"verify:web": "npm run build",
|
|
45
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
46
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
47
|
+
"eslint": "eslint . --ext ts",
|
|
48
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
49
|
+
"swiftlint": "node-swiftlint lint ios/Sources/NFCPlugin --config .swiftlint.yml",
|
|
50
|
+
"docgen": "docgen --api NFCPlugin --output-readme README.md --output-json dist/docs.json",
|
|
51
|
+
"build": "npm run clean && tsc && rollup -c rollup.config.js && rimraf *.tgz && npm pack",
|
|
52
|
+
"clean": "rimraf ./dist",
|
|
53
|
+
"watch": "tsc --watch",
|
|
54
|
+
"prepublishOnly": "npm run build"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@capacitor/android": "^6.0.0",
|
|
58
|
+
"@capacitor/core": "^6.0.0",
|
|
59
|
+
"@capacitor/docgen": "^0.2.2",
|
|
60
|
+
"@capacitor/ios": "^6.0.0",
|
|
61
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
62
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
63
|
+
"@ionic/swiftlint-config": "^1.1.2",
|
|
64
|
+
"@types/node": "^22.18.8",
|
|
65
|
+
"eslint": "^8.57.0",
|
|
66
|
+
"prettier": "^3.3.3",
|
|
67
|
+
"prettier-plugin-java": "^2.6.4",
|
|
68
|
+
"rimraf": "^3.0.2",
|
|
69
|
+
"rollup": "^2.32.0",
|
|
70
|
+
"swiftlint": "^1.0.1",
|
|
71
|
+
"typescript": "^5.9.3"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"@capacitor/core": ">=6.0.0 <9.0.0"
|
|
75
|
+
},
|
|
76
|
+
"prettier": "@ionic/prettier-config",
|
|
77
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
78
|
+
"eslintConfig": {
|
|
79
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
80
|
+
},
|
|
81
|
+
"capacitor": {
|
|
82
|
+
"ios": {
|
|
83
|
+
"src": "ios",
|
|
84
|
+
"podspec": "ExxiliCapacitorNfc.podspec"
|
|
85
|
+
},
|
|
86
|
+
"android": {
|
|
87
|
+
"src": "android"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|