Xcode - How to deal with notifications posted into NSNotificationCenter while application was in the background as soon as app comes to foreground

StackOverflow https://stackoverflow.com/questions/21700370

Question

I am currently dealing with Smartcard reader connected to a IOS device as an external accessory. When application goes to the background and remains there for a few (let's say 10-15 seconds) the reader is disconnected by iOS in order not to drain battery. This sends notification to NSNotificationCenter that the reader (EAAccessory) has been disconnected. When app comes to the foreground, it usually takes some time till the reader is connected back. I am able to handle with these notifications using following methods:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(EAaccessoryConnect) name:EAAccessoryDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(EAaccessoryDisConnect) name:EAAccessoryDidDisconnectNotification object:nil];

The problem is, sometimes when application is in the background for a longer time (longer than 20 minutes), more than one EAAccessoryDidDisconnectNotification is obviously posted to the notification centre as well as EAAccessoryDidConnectNotification. When I receive EAAccessoryDidDisconnectNotification I have to adequately handle it and allow some time till the EAAccessoryDidConnectNotification is received. However when another EAAccessoryDidDisconnectNotification comes, it messes up with my settings and the user is logged out from the application.

My question therefore is - is it possible to check which notifications have been sent to the NSNotificationCenter while app was in the background just after the app comes to the foreground, and remove multiple notification of the same kind - leaving only one notification of a kind. Or is there any other solution you suggest me to implement to deal with this?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top