From f3837c411ec3d47364f7c376dbd60a9247e513e0 Mon Sep 17 00:00:00 2001 From: Karibash Date: Tue, 21 Jul 2020 13:32:39 +0900 Subject: [PATCH] Add a command to send commands to MiFare tags --- RxCoreNFC.xcodeproj/project.pbxproj | 12 ++++++++++ .../RxNFCMiFareSendMiFareCommandResult.swift | 14 +++++++++++ Sources/NFCMiFareTag/NFCMiFareTag+Rx.swift | 24 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 Sources/NFCMiFareTag/Entity/RxNFCMiFareSendMiFareCommandResult.swift diff --git a/RxCoreNFC.xcodeproj/project.pbxproj b/RxCoreNFC.xcodeproj/project.pbxproj index 07bcf7a..50b7d43 100644 --- a/RxCoreNFC.xcodeproj/project.pbxproj +++ b/RxCoreNFC.xcodeproj/project.pbxproj @@ -33,6 +33,7 @@ E6A6ACC624C1D4C10069F67B /* RxNFCFeliCaRequestSystemCodeResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6A6ACC524C1D4C10069F67B /* RxNFCFeliCaRequestSystemCodeResult.swift */; }; E6A6ACC824C1D5450069F67B /* RxNFCFeliCaResetModeResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6A6ACC724C1D5450069F67B /* RxNFCFeliCaResetModeResult.swift */; }; E6A6ADD824C46CFA0069F67B /* RxNFCFeliCaSendFeliCaCommandResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6A6ADD724C46CFA0069F67B /* RxNFCFeliCaSendFeliCaCommandResult.swift */; }; + E6A6AE1024C5E1B60069F67B /* RxNFCMiFareSendMiFareCommandResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6A6AE0F24C5E1B60069F67B /* RxNFCMiFareSendMiFareCommandResult.swift */; }; E6BF06EC249C9D82007E84D3 /* RxCoreNFC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E6BF06E2249C9D82007E84D3 /* RxCoreNFC.framework */; }; /* End PBXBuildFile section */ @@ -75,6 +76,7 @@ E6A6ACC524C1D4C10069F67B /* RxNFCFeliCaRequestSystemCodeResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxNFCFeliCaRequestSystemCodeResult.swift; sourceTree = ""; }; E6A6ACC724C1D5450069F67B /* RxNFCFeliCaResetModeResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxNFCFeliCaResetModeResult.swift; sourceTree = ""; }; E6A6ADD724C46CFA0069F67B /* RxNFCFeliCaSendFeliCaCommandResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxNFCFeliCaSendFeliCaCommandResult.swift; sourceTree = ""; }; + E6A6AE0F24C5E1B60069F67B /* RxNFCMiFareSendMiFareCommandResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxNFCMiFareSendMiFareCommandResult.swift; sourceTree = ""; }; E6BF06E2249C9D82007E84D3 /* RxCoreNFC.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxCoreNFC.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E6BF06EB249C9D82007E84D3 /* RxCoreNFCTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RxCoreNFCTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -218,6 +220,7 @@ E6A6ADD524C302F80069F67B /* NFCMiFareTag */ = { isa = PBXGroup; children = ( + E6A6AE0E24C5E1990069F67B /* Entity */, E6A2A61B24A631B400282503 /* NFCMiFareTag+Rx.swift */, ); path = NFCMiFareTag; @@ -231,6 +234,14 @@ path = NFCTag; sourceTree = ""; }; + E6A6AE0E24C5E1990069F67B /* Entity */ = { + isa = PBXGroup; + children = ( + E6A6AE0F24C5E1B60069F67B /* RxNFCMiFareSendMiFareCommandResult.swift */, + ); + path = Entity; + sourceTree = ""; + }; E6BF06D8249C9D82007E84D3 = { isa = PBXGroup; children = ( @@ -378,6 +389,7 @@ E6A2A61624A6275500282503 /* NFCISO7816Tag+Rx.swift in Sources */, E6A6ADD824C46CFA0069F67B /* RxNFCFeliCaSendFeliCaCommandResult.swift in Sources */, E6A2A60E24A377A300282503 /* RxNFCTagReaderSessionEvent.swift in Sources */, + E6A6AE1024C5E1B60069F67B /* RxNFCMiFareSendMiFareCommandResult.swift in Sources */, E6A2A7F824C1646000282503 /* RxNFCFeliCaRequestServiceV2Result.swift in Sources */, E6A2A61A24A62D5400282503 /* RxNFCReaderError.swift in Sources */, E6A6ACC824C1D5450069F67B /* RxNFCFeliCaResetModeResult.swift in Sources */, diff --git a/Sources/NFCMiFareTag/Entity/RxNFCMiFareSendMiFareCommandResult.swift b/Sources/NFCMiFareTag/Entity/RxNFCMiFareSendMiFareCommandResult.swift new file mode 100644 index 0000000..8cb4acb --- /dev/null +++ b/Sources/NFCMiFareTag/Entity/RxNFCMiFareSendMiFareCommandResult.swift @@ -0,0 +1,14 @@ +// +// RxNFCMiFareSendMiFareCommandResult.swift +// RxCoreNFC +// +// Created by Karibash on 2020/07/20. +// Copyright © 2020 Karibash. All rights reserved. +// + +import Foundation + +@available(iOS 13.0, *) +public struct RxNFCMiFareSendMiFareCommandResult { + let data: Data +} diff --git a/Sources/NFCMiFareTag/NFCMiFareTag+Rx.swift b/Sources/NFCMiFareTag/NFCMiFareTag+Rx.swift index 6ade747..7353489 100644 --- a/Sources/NFCMiFareTag/NFCMiFareTag+Rx.swift +++ b/Sources/NFCMiFareTag/NFCMiFareTag+Rx.swift @@ -11,4 +11,28 @@ import RxSwift @available(iOS 13.0, *) extension ObservableType where Element == NFCMiFareTag { + + // MARK: - Commands - + + /// Sends a native MiFare command to the tag. + /// - Important: For NFCMiFareFamily.ultralight commands, you must calculate a 2-byte CRC value and append it to the end of the command data. + /// - Parameter commandPacket: A MiFare command. + /// - Returns: An NSData object containing the tag's response data for the command. + public func sendMiFareCommand(commandPacket: Data) -> Observable { + flatMap { tag in + Single.create { observer in + tag.sendMiFareCommand(commandPacket: commandPacket) { data, error in + if error != nil { + observer(.error(error!)) + } else { + observer(.success(RxNFCMiFareSendMiFareCommandResult( + data: data + ))) + } + } + return Disposables.create() + } + } + } + }