Taplinx iOS app reading Desfire EV2

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Taplinx iOS app reading Desfire EV2

155 Views
Octopussy
Contributor I

Hi,

I new to the Taplinx for iOS. I'm working on an app to read Desfire EV2 app data. I'm quite experienced with iOS development. I got an app running but I'm not sure how to correctly initiate a getDESFireEV2Instance to select the app and then start to read using authentication. My first step is to actually get the tag details and select the app.

When I call "libraryManager.getTagDetails" the app always crashes. Probably my calling sequence is still wrong.

verifyLicense is implemented and works

Attached is my code that I have so far.

I really hope someone would be able to point me into the right direction.

Thanks so much,

Martin

 

class NFCReader: NSObject, NFCTagReaderSessionDelegate, TapLinxApduHandlerProtocol {
	var session: NFCTagReaderSession?
	var handler: TapLinxApduHandler = TapLinxApduHandler()
	let libraryManager = TLLibraryManager()

	func startSession() {
		session = NFCTagReaderSession(pollingOption: .iso14443, delegate: self, queue: nil)
		session?.alertMessage = "Hold your iPhone near the NFC tag."
		session?.begin()
	}
	
	func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) {
		print("NFCReader.tagReaderSessionDidBecomeActive: Session active.")
	}
	
	func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) {
		print("NFCReader.tagReaderSessionDidBecomeActive: Session invalidated: \(error.localizedDescription)")
	}
	
	func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
		guard let firstTag = tags.first else {
			print("NFCReader.tagReaderSession: No tags detected.")
			session.invalidate(errorMessage: "No tags detected.")
			return
		}
		
		switch firstTag {
			case .miFare(let miFareTag):
				print("NFCReader.tagReaderSession.connect(to): miFareTag detected")
				self.handleMiFareTag(miFareTag, session: session)
			default:
				print("NFCReader.tagReaderSession.connect(to): Unsupported tag type: \(firstTag)")
				session.invalidate(errorMessage: "Unsupported tag type.")
		}
	}
	
	
	private func handleMiFareTag(_ tag: NFCMiFareTag, session: NFCTagReaderSession) {
		print("handleMiFareTag")
		let reader = TL_IOSNFCReader(uid: tag.identifier, historicalBytes: Data())
		handler = TapLinxApduHandler(reader: reader)
		handler.delegate = self
		libraryManager.setApduHandlerWithApduHandler(handler)
		libraryManager.getTagDetails { tagDetails, success in
			print("getTagDetails: \(success)")
		}
		libraryManager.getDESFireEV2Instance().selectApplication(withAppID: appID) { result in
			print("result: \(result)")
		}
		
//		let desFireEV2 = libraryManager.getDESFireEV2Instance()
//		desFireEV2.getVersionOnCompletion { version, x  in
//			//print("DESFire EV2 Version \(version) - \(x)")
//		}
	}
	
	func apduExchange(withByteArray apduData: Data) -> TL_TagAPDUResponse? {
		var tagAPDUResponse: TL_TagAPDUResponse?
		print("MIFARE CAPDU -> \(apduData.hex)")
		
		return tagAPDUResponse
	}
}

 

 

Labels (2)
0 Kudos
Reply
4 Replies

68 Views
Octopussy
Contributor I

Hi ukcas,

unfortunately the call 

var libraryManager : TLLibraryManager! = TLLibraryManager.shared()

 

will crash. Here is the crash log.

Octopussy_0-1734436722982.png

So there seems to be something wrong with the "TLLibraryManager.shared()" call.

If you want I can send you a bare bone project that shows the issue.

Thanks very much,

Martin

 

 

0 Kudos
Reply

78 Views
ukcas
NXP Employee
NXP Employee

Dear Octopussy,

TLLibraryManager is a singleton class and we have a class method +(TLLibraryManager *)shared.

 

Try to instantiate like:

 

import UIKit
import CoreNFC
import Network
 
class ViewController: UIViewController {
    
    lazy var downloadQueue: OperationQueue = {
        var queue = OperationQueue()
        queue.name = "Execute Commands queue"
        queue.maxConcurrentOperationCount = 1
        return queue
    }()
    
    @IBOutlet var scanButton: UIButton? = UIButton()
    
    var connectedTag: NFCISO7816Tag?
    var connectedMifareTag: NFCMiFareTag?
    var tagReaderSession: NFCTagReaderSession!
    var uid = ""
    var isExecutingSelectedCommands = false
    var CommandsToExecute = [String]()
    var handler = TapLinxApduHandler()
    var currentTag: TL_TagInfo?
 
    var libraryManager : TLLibraryManager! = TLLibraryManager.shared()
...

func testMIFARELibraryManagerInstance() {
        let libraryMangager = TLLibraryManager.shared()
        XCTAssertNotNil(libraryMangager)
    }
...

 

 

0 Kudos
Reply

130 Views
Fabian_R
NXP TechSupport
NXP TechSupport

Hello, 

Thank you very much for working with us.

Unfortunately, we don't have an example for running in iOS but my recommendation would be to please check the Android example for NTAG and start by adapting this application to iOS. When you are able to correctly implement it on iOS I'm sure it will get easier.

Additionally, please let me know if you have already check the javadoc available in Taplinx site.

Best Regards,
Fabian
0 Kudos
Reply

110 Views
Octopussy
Contributor I

Hi Fabian,

the iOS TapLinx library is quite different from the Android one. The issue I'm having is that the initialization of the "TLLibraryManager" doesn't seem to work as expected. 

 

	let libraryManager = TLLibraryManager()
	libraryManager.getDESFireEV2Instance().selectApplication(withAppID: appID) { result in
			print("result: \(result)")
		}

 

This will always result in a crash. So it looks like the instantiation of the "TLLibraryManager" is wrong.

Calling 

 

TLLibraryManager.shared()

 

will also crash right away. But calling

 

TapLinxLibrary.shared()

 

works. so there seems to be an issuer on how the "TLLibraryManager" need to be instantiated.

I would need some help on how to instantiated the "TLLibraryManager" correctly so I can make additional call then.

Thanks,

Martin

Tags (1)
0 Kudos
Reply