schorschii / MensaGuthaben-iOS

Read the balance of your mensa/canteen card
GNU General Public License v3.0
24 stars 3 forks source link

App crashes on trying to read card ID #1

Closed kiliankoe closed 5 years ago

kiliankoe commented 5 years ago

Hi!

First of all, huge thanks for this application! I've been interested in decoding Emeal data on iOS for quite a while now and am super happy to see that CoreNFC finally allows doing so.

Everything works great when using the app from the App Store, but when running it built from the code available here, I'm getting an out-of-bounds exception on trying to decode the card ID in the following snippet in MainViewController.

let idInt = idData.withUnsafeBytes {
    $0.load(as: Int.self)
}

Any idea what's happening here?

Thanks!

schorschii commented 5 years ago

Hi @kiliankoe , after installing the latest Xcode update I discover the same problem. But interestingly only in debug mode: this means when I export the app "Ad Hoc" (as .ipa) and install it via Apple Configurator, the app works without crashing. Strange. The reason seams to be that tag.identifier returns a 7 byte long data value, but you need 8 bytes for a successful conversion to Integer. So my solution is to insert a zero byte into idData. This solution works, it prints out the correct card ID.

if(idData.count == 7) {
    idData.append(UInt8(0))
}

Thanks for reporting! Greetings from Dresden to Dresden :)

kiliankoe commented 5 years ago

Huh, interesting bug. But thanks for the workaround! 😊