Search code examples
core-nfc

How to avoid NFCError Code=203 "Session is invalidated due to system resource is unavailable"?


When I try to start a CoreNFC session, it first works but then, after a few times, I get an error message:

Error Domain=NFCError Code=203 "Session is invalidated due to system resource is unavailable"

Reading NFC tags is no longer possible until I restart my iPhone.

Why does this error occur? What can I do to avoid it?


Solution

  • I found the solution to the problem:

    What is happening? When I initiate an NFC reader session by holding the iPhone upside down, a UIDeviceOrientationDidChangeNotification is delivered also when the app is inactive. When this happens, iOS cannot start an NFC reading session and it probably records the problem and does not even try in the future until the iPhone was restarted.

    Solution: Before I start an NFC reader session, I make sure that the app is active:

    [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive