semlette / nfc_in_flutter

Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.
MIT License
120 stars 119 forks source link

App crashes in older iphones with no nfc #20

Closed rohnsht closed 4 years ago

rohnsht commented 4 years ago

I added the package to my app, it works fine from iphone 7 and up but it crashes the app at startup in iphones older then iphone7 which don't possess nfc.

semlette commented 4 years ago

Hi!

I am not able to reproduce this as I only have a iPhone 8 which does support NFC. Even running the example app in the iOS simulator (iPhone 7 and 8) doesn't cause it to crash.

viskanic commented 4 years ago

Hello everyone,

you can't reproduce the NFC related crash on a simulator, the same way you can't use the camera on the simulator.

The crash happens on any device with a iOS version lower than 13.

I hope this helps.

BR

semlette commented 4 years ago

Well I don't have any devices running iOS <13 so I can't test it at all.

If any of you do, please send the crash stack trace or similar.

viskanic commented 4 years ago

Hello,

the thing is there is no stack. The app crashes instantly. The only thing you can see is a flash of the app being opend and closed in the same instant.

Had a similar issue with another dependency that was failing the app in release mode.

The only thing you see in the console after installing the app is : "Connection closed before full header was received"

I'm sorry I don't have more info to share.

The only thing that comes to mind at the moment is wrapping the plugin in a big :

if (@available(iOS 13.0, *))

BR

semlette commented 4 years ago

Perhaps it is because the CoreNFC framework is not weakly linked?

martyfuhry commented 4 years ago

It's an issue with the CoreNFC framework not being available on older devices. I was testing on my iPhone 5 running iOS 10.3.3 and got this error:

dyld: Library not loaded: /System/Library/Frameworks/CoreNFC.framework/CoreNFC
  Referenced from: /var/containers/Bundle/Application/41338648-F28E-4864-900B-BB90F9DE5F4D/Runner.app/Runner
  Reason: image not found

After a bunch of searching through StackOverflow and some trial and error, I was able to solve this. Add the CoreNFC.framework in General -> Frameworks, Libraries, and Embedded Content. Set the Embed value to "Do Not Embed". Then, head over to Build Phases -> Link Binary With Libraries, and find (or add) CoreNFC.framework and mark the status as "Optional".

I also had to clean and rebuild about 100 times. But I can confirm it works when built for physical devices (on an iPhone 5, and on an iPhone 8).

I'd suggest adding this to the FAQ or setup, unless there's some magic way you can tell the plugin to set it up like this. The plugin works great by wrapping everything around "NFC.isNDEFSupported", so you wouldn't expect a hard iOS 13 and up dependency.

semlette commented 4 years ago

I just merged PR #28 which changed the Podspec file to have the CoreNFC framework be a weak framework instead.

@rohnsht does this fix the issue for you?

semlette commented 4 years ago

Can any of you confirm if this is fixed or not with #28?

dependencies:
  nfc_in_flutter:
    git:
      url: git://github.com/semlette/nfc_in_flutter.git
      ref: 4c1b73f5d024fac7d25ac909f5d47796a53e5e3e
semlette commented 4 years ago

I am going to assume #28 fixed it. I am closing the issue, but will reopen it again if it didn't actually fix it.

logemann commented 1 year ago

@martyfuhry how did you even manage to be able to offer this app for iPhone 6s and older devices? We are struggling to make it available on older phones since it always say iPhone 7 and never in the store. Cant even find a setting to specify devices... only iOS versions...

martyfuhry commented 1 year ago

@martyfuhry how did you even manage to be able to offer this app for iPhone 6s and older devices? We are struggling to make it available on older phones since it always say iPhone 7 and never in the store. Cant even find a setting to specify devices... only iOS versions...

I struggled. And now I've switched to nfc_manager. I think this project has been abandoned and I haven't had any trouble with nfc_manager.