2

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?

John
  • 8,468
  • 5
  • 36
  • 61

2 Answers2

1

Try adding this line after you have finished reading the NDEF:

[session invalidateSession];

or in Swift:

session.invalidate()

This tip was mentioned in Boris's answer to: iOS 11 Core NFC - any sample code?

Apparently if you don't invalidate the session object, it doesn't always release the resource. I didn't have a problem for months, then suddenly a few days ago it started doing it all the time. This seems to have fixed it.

Let us know if it works for you; it would be good to have more than one data point.

Alexander M.
  • 3,308
  • 2
  • 20
  • 31
Blisterpeanuts
  • 844
  • 1
  • 10
  • 16
  • i wonder why this doesnt fix it if I change the bundle id for the app. Does this mean that if this error appears in one app, other apps also cannot create session? – Klemen Apr 26 '18 at 19:49
  • After invalidating, you also need to create a new session with something like: `self.nfcSession = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false)` – Justin Vallely Jun 08 '18 at 20:12
0

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
John
  • 8,468
  • 5
  • 36
  • 61