ExternalAccessory and NSUserDefaults strange problem

I work with ExternalAccessory FW and can transfer data to a peripheral device.

I came across a strange situation when trying to save some value in NSUserDefaults I get this (similar) unrelated error:

 UISupportedExternalAccessoryProtocols = com.xxxxx.yyy.zz 2013-07-24 17:01:39.181 myApp[791:907] ERROR - opening session failed 2013-07-24 17:01:39.182 myApp[791:907] ERROR - /SourceCache/ExternalAccessory/ExternalAccessory-213.3/EASession.m:-[EASession dealloc] - 137 unable to close session for _accessory=0x2088cdb0 and sessionID=65536 

And the connection to the periphery is dead.

Code that is written to NSUserDefaults :

 NSInteger transactionId = [[NSUserDefaults standardUserDefaults] integerForKey:kTransactionId]; transactionId = transactionId % NSIntegerMax + 1; [[NSUserDefaults standardUserDefaults] setInteger:transactionId forKey:kTransactionId]; [[NSUserDefaults standardUserDefaults] synchronize]; 

If I comment [[NSUserDefaults standardUserDefaults] setInteger:transactionId forKey:kTransactionId]; , Everything will be fine...

Any idea?

+4
source share
1 answer

NSUserDefaults runs in the main thread. Perhaps you want to use something else, perhaps an NSMutableDictionary, which is then serialized to disk.

0
source

Source: https://habr.com/ru/post/1493216/


All Articles