I don’t see why the optional type should be a problem. If evInstance would have been nil, it would not run the method at all.
The functions “selectApplication” and “createStandardFile” are not the problem. Those functions do work. I mentioned them to indicate that the notation of the “applicationId” is accepted in these methods.
I get this error when executing “createApplication” with every possible “applicationId” I choose. The exception I get is from the method “createApplication”. It would not even return this exception if evInstance was nil.
Removing the optional type did not solve the issue. Below a simplified version of my code.
self.libraryManager = TLLibraryManager.shared()
let evInstance = self.libraryManager.getDESFireEV3Instance()
print("\n=== Step 1: app main selecting... ===")
evInstance.selectApplicationPICCP1() { isSuccess in
print("=== app main selected ===")
print("isSuccess: \(isSuccess)")
}
print("\n=== Step 2: app authenitcating... ===")
evInstance.authenticate(
withCardKeyNo: 0,
withAuthenticationType: .native,
withAuthKeyType: .THREEDES,
withCommandSetForAuth: .Native,
withAuthkey: key)
{ isSuccess in
print("=== app authenticated ===")
print("isSuccess: \(isSuccess)")
}
print("\n=== Step 3: app creating... ===")
let appSettings = CreateAppSettingsModel()
appSettings.appKeySettingChangable = true
appSettings.authRequiredForFileManagement = false
appSettings.authRequiredForFileConfiguration = false
appSettings.numberOfKeySets = 2
appSettings.keyType = .AES128
appSettings.maxKeySize = 32
appSettings.masterKeyInterchangable = true
evInstance.createApplication(withAppID: 0x111111, withNumberOfBytes: 160, withAppSettings: appSettings)
{ isSuccess in
print("\n=== app created ===")
print("isSuccess: \(isSuccess)")
}
This results in the log below, with the exception at the bottom thrown by "createApplication".
initializeTapLinxLibrary
responseString License Verified Successfully, Time to explore Taplinx Library
Tag reader did become active <NFCTagReaderSession: 0x1054c7a20>
isReady: true
didDetect [CoreNFC.NFCTag.miFare(<NFCMiFareTag: 0x10569a0c0>)]
MiFare card found
Connected to tag
=== Step 1: app main selecting... ===
Command sent to card : 5A000000
[general] response.tag.type: (null)
[general] response.responseData: {length = 1, bytes = 0x00}
Response received : 00
=== app main selected ===
isSuccess: true
=== Step 2: app authenitcating... ===
AuthType - Native KeyType - THREEDES KeyInfo.KeyArray - {length = 16, bytes = 0x00000000000000000000000000000000}, cardKeyNo - 0
Command sent to card : 0A00
[general] response.tag.type: (null)
[general] response.responseData: {length = 9, bytes = 0xaf68e6008758263832}
Response received : AF68E6008758263832
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x68e6008758263832}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x85b208b0762265d7}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x8b32a8922dac433b}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
Command sent to card : AFE7109DBEE0E8FD8B7E6B593689DFA4EF
[general] response.tag.type: (null)
[general] response.responseData: {length = 9, bytes = 0x00373c4845f783cf52}
Response received : 00373C4845F783CF52
DES Session Key Before - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data After - <ComNxpNfclibDefaultimplKeyData: 0x10554c120>
DES Session Key Data Array After - {length = 16, bytes = 0x00000000000000000000000000000000}
------ DES, {length = 8, bytes = 0x373c4845f783cf52}, {length = 16, bytes = 0x00000000000000000000000000000000}, (null) ------
=== app authenticated ===
isSuccess: true
=== Step 3: app creating... ===
Max Size - 32
Key Type - AES128
com.nxp.nfclib.exceptions.UsageException: Application ID [appId] must be 3 bytes
=== app created ===
isSuccess: false