Reading eID with NFC crushing in production build but it works in debug mode - swift

I have a React-Native application and I implemented a 3rd party eID NFC Reader SDK. This 3rd SDK is using NFCPassportReader library and CoreNFC package also. I'm trying to read Turkish Citizenship eID with this module. My problem this module is working properly in debug mode but It's crushing in release version. I've added a crush log related to this issue and I've added tagReaderSession implementation code. I've added my "com.apple.developer.nfc.readersession.iso7816.select-identifiers" configuration code also.
Does anybody have an idea about that problem?
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region. Bytes before following region: 4340301824
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 102b3c000-10603c000 [ 53.0M] r-x/r-x SM=COW ...ePieMobileDev
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [9236]
Triggered by Thread: 8
Thread 8 name: Dispatch queue: com.apple.corenfc.readersession.delegate
Thread 8 Crashed:
public func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
Log.debug( "tagReaderSession:didDetect - \(tags[0])" )
if tags.count > 1 {
Log.debug( "tagReaderSession:more than 1 tag detected! - \(tags)" )
let errorMessage = NFCViewDisplayMessage.error(.MoreThanOneTagFound)
self.invalidateSession(errorMessage: errorMessage, error: NFCPassportReaderError.MoreThanOneTagFound)
return
}
let tag = tags.first!
var passportTag: NFCISO7816Tag
switch tags.first! {
case let .iso7816(tag):
passportTag = tag
default:
Log.debug( "tagReaderSession:invalid tag detected!!!" )
let errorMessage = NFCViewDisplayMessage.error(NFCPassportReaderError.TagNotValid)
self.invalidateSession(errorMessage:errorMessage, error: NFCPassportReaderError.TagNotValid)
return
}
// Connect to tag
Log.debug( "tagReaderSession:connecting to tag - \(tag)" )
session.connect(to: tag) { [unowned self] (error: Error?) in
if error != nil {
Log.debug( "tagReaderSession:failed to connect to tag - \(error?.localizedDescription ?? "Unknown error")" )
let errorMessage = NFCViewDisplayMessage.error(NFCPassportReaderError.ConnectionError)
self.invalidateSession(errorMessage: errorMessage, error: NFCPassportReaderError.ConnectionError)
return
}
Log.debug( "tagReaderSession:connected to tag - starting authentication" )
self.updateReaderSessionMessage( alertMessage: NFCViewDisplayMessage.authenticatingWithPassport(0) )
self.tagReader = TagReader(tag:passportTag)
if let newAmount = self.dataAmountToReadOverride {
self.tagReader?.overrideDataAmountToRead(newAmount: newAmount)
}
self.tagReader!.progress = { [unowned self] (progress) in
if let dgId = self.currentlyReadingDataGroup {
self.updateReaderSessionMessage( alertMessage: NFCViewDisplayMessage.readingDataGroupProgress(dgId, progress) )
} else {
self.updateReaderSessionMessage( alertMessage: NFCViewDisplayMessage.authenticatingWithPassport(progress) )
}
}
DispatchQueue.global().async {
self.startReading( )
}
}
}
<key>NFCReaderUsageDescription</key>
<string>Read the NFC chip of ePassports</string>
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
<string>A0000002471001</string>
</array>
Video recording of this issue:
https://vimeo.com/784270897
I can run the application in debug mode without any problems, but when I start reading nfc in release mode, the application crashes.

Related

Connect multiple AVAudioMixerNodes to AVAudioEngine

I'm having a crash when I try connecting two AVAudioMixerNodes to the microphone input of AVAudioEngine.
I couldn't find documentation online how to manage two or more nodes to the same input.
What is the proper way to handle that case where you have multiple node listening to the microphone?
I'm calling those three method of after the other on the background thread:
private func setupSession() {
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(.playAndRecord, options: [.mixWithOthers])
if session.isInputGainSettable {
try session.setInputGain(0.2)
}
try session.setActive(true, options: .notifyOthersOnDeactivation)
} catch let error as NSError {
LoggerManager.shared.error(error: error, message: "Error while setting up AVAudioSession Category/Active status")
}
}
private func setupMixerNodes() {
analyzerNode = AVAudioMixerNode()
analyzerNode.volume = 0
volumeNode = AVAudioMixerNode()
volumeNode.volume = 0
engine.attach(analyzerNode)
engine.attach(volumeNode)
}
private func makeConnections() {
/* input microphone */
let inputNode = engine.inputNode
let inputFormat = inputNode.outputFormat(forBus: 0)
let analyzerConnectionPoint = AVAudioConnectionPoint(node: analyzerNode, bus: 0)
let volumeConnectionPoint = AVAudioConnectionPoint(node: volumeNode, bus: 0)
engine.connect(inputNode, to: [analyzerConnectionPoint, volumeConnectionPoint], fromBus: 0, format: inputFormat)
let mainMixerNode = engine.mainMixerNode
let mixerFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: inputFormat.sampleRate, channels: 1, interleaved: false)
engine.connect(analyzerNode, to: mainMixerNode, fromBus: 0, toBus: 0, format: mixerFormat)
engine.connect(volumeNode, to: mainMixerNode, fromBus: 0, toBus: 1, format: mixerFormat)
}
and I get this crash:
AURemoteIO.cpp:1128 failed: -10851 (enable 1, outf< 2 ch, 0 Hz, Float32, deinterleaved> inf< 2 ch, 0 Hz, Float32, deinterleaved>)
2022-03-08 12:59:57.950612-0500 SnoreLabo[2914:456147] [avae] AVAEInternal.h:76 required condition is false: [AVAudioEngineGraph.mm:2401:ConnectMultipleOutputs: (IsFormatSampleRateAndChannelCountValid(format))]
2022-03-08 12:59:58.030789-0500 SnoreLabo[2914:456147] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
*** First throw call stack:
(0x18273ed3c 0x199aa36a8 0x1828085bc 0x1ddf44eac 0x1ddf9b020 0x1de01bfa0 0x1de018328 0x104d4db1c 0x104d4e1f8 0x104ed4f6c 0x104bcdbe8 0x10dc00718 0x10dc01f94 0x10dc13edc 0x10dc146fc 0x1dcc4ae48 0x1dcc4a9f0)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
terminating with uncaught exception of type NSException
EDIT
I ended up using this:
print("Current category: \(AVAudioSession.sharedInstance().category)")
engine.connect(inputNode, to: [analyzerConnectionPoint, volumeConnectionPoint], fromBus: 0, format: inputFormat)
But I still get the same crash from time to time... And the category is properly set to .playAndRecord when it crash so that's not the issue...

cloudkit+coredata syncing stopped, how to restore syncing?

My app uses cloudkit+coredata, syncing works fine util i found recent items not appear on another iphone one day, I think the syncing stopped. so i add some debug information and error occurs:
21-12-10 16:13:58.089 CKDBManager[128], processCloudkitEventChanged(:)[c]: Event(setup) started
21-12-10 16:13:58.301 CKDBManager[133], processCloudkitEventChanged(:)[c]: Event(setup) finished in 0.21s with success
21-12-10 16:14:01.218 CKDBManager[128], processCloudkitEventChanged(:)[c]: Event(setup) started
21-12-10 16:14:01.280 CKDBManager[133], processCloudkitEventChanged(:)[c]: Event(setup) finished in 0.06s with success
21-12-10 16:14:01.286 CKDBManager[128], processCloudkitEventChanged(:)[c]: Event(import) started
21-12-10 16:14:02.372 CKDBManager[133], processCloudkitEventChanged(:)[c]: Event(import) finished in 1.09s with success
21-12-10 16:14:02.378 CKDBManager[128], processCloudkitEventChanged(:)[c]: Event(export) started
21-12-10 16:14:02.388 CKDBManager[133], processCloudkitEventChanged(:)[c]: Event(export) finished in 0.01s with success
21-12-10 16:14:12.741 CKDBManager[128], processCloudkitEventChanged(:)[c]: Event(export) started
21-12-10 16:14:12.756 CKDBManager[133], processCloudkitEventChanged(:)[c]: Event(export) finished in 0.02s with success
21-12-10 16:14:12.762 CKDBManager[128], processCloudkitEventChanged(:)[c]: Event(import) started
21-12-10 16:14:13.169 CKDBManager[131], processCloudkitEventChanged(:)[c]: Event(import) error: Error Domain=CKErrorDomain Code=12 "(null)"
first, I cannot find description of CKErrorDomain Code=12. but the most important is how can i restore syncing between coredata and cloudkit without data loss on iphone(already so many data)?
the code shows as following:
NotificationCenter.default
.publisher(for: NSPersistentCloudKitContainer.eventChangedNotification)
.sink { [weak self] notification in
guard let self = self else { return }
self.processCloudkitEventChanged(notification)
}
.store(in: &subscriptions)
private func processCloudkitEventChanged(_ notification: Notification) {
guard let cloudEvent = notification.userInfo?[NSPersistentCloudKitContainer.eventNotificationUserInfoKey]
as? NSPersistentCloudKitContainer.Event else { return }
var eventTypeString = "";
switch cloudEvent.type {
case .setup: eventTypeString = "setup"
case .import: eventTypeString = "import"
case .export: eventTypeString = "export"
#unknown default: eventTypeString = "unknown"
}
if cloudEvent.endDate == nil {
foolPrint("Event(\(eventTypeString)) started")
} else {
if let error = cloudEvent.error {
foolPrint("Event(\(eventTypeString)) error: \(error)")
} else {
foolPrint("Event(\(eventTypeString)) finished in \(String(format: "%.2f", cloudEvent.endDate?.timeIntervalSince(cloudEvent.startDate) ?? 0))s with \(cloudEvent.succeeded ? "success" : "failure")")
}
}
}
error logs after enable system cloudkit debug info:
2021-12-10 17:34:44.041410+0800 Listening[30856:17878746] [error] error: CoreData+CloudKit: -NSCloudKitMirroringDelegate recoverFromError:: <NSCloudKitMirroringDelegate: 0x2834d0000> - Attempting recovery from error: <CKError 0x2800e4b40: "Partial Failure" (2/1011); "Failed to modify some record zones"; uuid = 4A785529-CF0B-42E4-99B5-5x; container ID = "iCloud.com.y.x"; partial errors: {
com.apple.coredata.cloudkit.zone:defaultOwner = <CKError 0x2800fca80: "Server Rejected Request" (15/2027); server message = "Custom zones are not allowed in public DB"; op = 8C27C3373F4F1480; uuid = 4A785529-CF0B-42E4-99B5-5x>
}>
NSCloudKitMirroringDelegate: 0x2834d40d0> - Ignoring remote change notification because it's for a different store: 2B6EC011-682C-4F95-x-910FC6ECDB81 / 2B6EC011-682C-4F95-x-910FC6ECDB81

"Missing required entitlement" for NFCISO15693Tag customCommand

In iOS13 beta version. when I tried use the NFCISO15693Tag api
customCommandWithRequestFlag:customCommandCode:customRequestParameters:completionHandler:
send customCommand code to the tag ,
I got the error:
-[NFCTagReaderSession transceive:tagUpdate:error:]:706 Error Domain=NFCError Code=2 "Missing required entitlement" UserInfo={NSLocalizedDescription=Missing required entitlement}
I have tried:
1, Reconfig the Privacy of NFC.
2, Add the config in my info.plist
<key>com.apple.developer.nfc.readersession.felica.systemcodes</key>
<array>
<string>12FC</string>
</array>
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
<string>D2760000850101</string>
</array>
But , none of them work for me .
The following is my source code:
func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
if let st = tags.first {
session.connect(to: st) { (error) in
if error != nil {
session.invalidate(errorMessage: "Connection error. Please try again.")
return
}
if case let .iso15693(type5Tag) = st {
print(type5Tag.identifier.toString())
print(type5Tag.icSerialNumber.toString())
print(type5Tag.isAvailable)
type5Tag.select(requestFlags: [.address, .highDataRate]) { (selectError) in
print("selectError")
print(selectError)
}
type5Tag.customCommand(requestFlags: [.highDataRate, .address], customCommandCode: 0xB4, customRequestParameters: Data([0x02])) { (data, error) in
print("custom command: get random number")
print(data.toString())
print(error)
}
}
}
}
Actually, I get the following error:
-[NFCTagReaderSession transceive:tagUpdate:error:]:706 Error Domain=NFCError Code=2 "Missing required entitlement" UserInfo={NSLocalizedDescription=Missing required entitlement}
expect 4 bytes random number.

SSAccountStore: Unable to get the local account. error = Error Domain=SSErrorDomain Code=100

I am having trouble getting access to the users Apple Music.
The error I am getting is
[core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-02-04 19:14:37.250467+0900 SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-02-04 19:14:37.252008+0900 [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-02-04 19:14:37.252051+0900 SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-02-04 19:14:37.253604+0900 SSAccountStore: Unable to get the local account. error = Error Domain=SSErrorDomain Code=100 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store}
However the weird part of this code is that I am also able to retrieve the Music User Token.
Is there sth that I am missing?
Any help is appreciated.
static func auth(){
let cloudServiceController = SKCloudServiceController()
let developerToken = "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyz"
SKCloudServiceController.requestAuthorization { status in
guard status == .authorized else { return }
}
cloudServiceController.requestCapabilities { capabilities, error in
guard capabilities.contains(.musicCatalogPlayback) else { return }
}
cloudServiceController.requestUserToken(forDeveloperToken: developerToken, completionHandler: { token, error in
guard let token = token else { return }
UserDefaults.standard.set(token, forKey: "MUSIC_USER_TOKEN")
UserDefaults.standard.set(developerToken, forKey: "DEVELOPER_TOKEN")
print("Music User Token:", token)
})
}
I think you have to call
cloudServiceController.requestUserToken
once user has authorised after completion handler for SKCloudServiceController.requestAuthorization
I was having this same issue until I removed Bearer from the beginning of developerToken.
OP's code example has developerToken set to "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyz", so I can only assume if OP is including Bearer at the beginning or not.
So to be more clear, this is what I was doing before:
asyncAskMyServerToGenerateMyAppleMusicDeveloperJWTDevToken { rawDevToken in
let formattedDeveloperToken = "Bearer \(rawDevToken)"
SKCloudServiceController().requestUserToken(forDeveloperToken: formattedDeveloperToken)
{ possibleToken, _ in
if let userMusicToken = possibleToken
{
YayIGotIt.forTheWin(userMusicToken)
}
}
}
And this is what I did to make it actually work:
asyncAskMyServerToGenerateMyAppleMusicDeveloperJWTDevToken { rawDevToken in
//Not prepending "Bearer " anymore
SKCloudServiceController().requestUserToken(forDeveloperToken: rawDevToken)
{ possibleToken, _ in
if let userMusicToken = possibleToken
{
YayIGotIt.forTheWin(userMusicToken) //This actually fires now
}
}
}

How to connect to Socket.IO swift?

I am having trouble connecting to Socket.IO chat..
import UIKit
import SocketIO
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let manager = SocketManager(socketURL: URL(string: "wss://socket-io-chat.now.sh/socket.io/")!, config: [.log(true), .compress])
let socket = manager.defaultSocket
socket.on(clientEvent: .connect) {data, ack in
print("socket connected")
}
socket.on("new message") {data, ack in
print("new Messages")
}
socket.connect()
}
}
I am using the latest socket.io library and already added app transport in info.plist.
here's what the logs says..
2018-01-22 16:56:46.316676+0800 ExampleSocket[6963:2231315] LOG SocketEngine: Got message: 40
2018-01-22 16:56:46.317249+0800 ExampleSocket[6963:2231315] LOG SocketEngine: Writing poll: has data: false
2018-01-22 16:56:46.317771+0800 ExampleSocket[6963:2231315] LOG SocketEnginePolling: Sending poll: as type: 2
2018-01-22 16:56:46.323959+0800 ExampleSocket[6963:2231318] TIC Read Status [2:0x0]: 1:57
2018-01-22 16:56:46.324082+0800 ExampleSocket[6963:2231318] TIC Read Status [2:0x0]: 1:57
2018-01-22 16:56:46.330099+0800 ExampleSocket[6963:2231315] LOG SocketEnginePolling: Created POST string: 1:2
2018-01-22 16:56:46.330615+0800 ExampleSocket[6963:2231315] LOG SocketEnginePolling: POSTing
2018-01-22 16:56:46.330744+0800 ExampleSocket[6963:2231315] LOG SocketEngine: Engine is being released
try the below code:
var socketClient: SocketIOClient!
if let url = URL(string: "wss://socket-io-chat.now.sh/socket.io/") {
let socketClient = SocketIOClient(socketURL: url, config: [.log(true),.forcePolling(true)])
socketClient.connect()
}
socketClient.onAny { (socEvent) in
if let status = socEvent.items as? [SocketIO.SocketIOClientStatus] {
if let first = status.first {
switch first {
case .connected:
print("Socket: connected")
break
case .disconnected:
print("Socket: disconnected")
break
case .notConnected:
print("Socket: notConnected")
break
case .connecting:
print("Socket: connecting")
break
}
}
}
}