toga icon indicating copy to clipboard operation
toga copied to clipboard

Create libraries for NFC reader APIs

Open gy-mate opened this issue 1 year ago • 4 comments

What is the problem or limitation you are having?

Toga doesn't support NFC readers.

Describe the solution you'd like

Support NFC readers on Android and iOS.

Describe alternatives you've considered

Using native platform APIs. But learning and implementing them separately can be time-consuming.

Additional context

This was already suggested several times:

  • https://discord.com/channels/836455665257021440/836455665257021443/1050878483678646392
  • https://discord.com/channels/836455665257021440/836455665257021443/1158711066004574238
  • https://discord.com/channels/836455665257021440/836455665257021443/1300540888833069087

For iOS it should be implemented here, I guess: https://github.com/beeware/toga/tree/main/iOS/src/toga_iOS/libs And here for Android: https://github.com/beeware/toga/tree/main/android/src/toga_android/hardware

iOS documentation: https://developer.apple.com/documentation/corenfc Android: https://developer.android.com/develop/connectivity/nfc/nfc Web: https://developer.mozilla.org/en-US/docs/Web/API/Web_NFC_API

gy-mate avatar Nov 19 '24 09:11 gy-mate

Similarly to Bluetooth (#2915), it would be better to contribute Android and iOS support to an existing cross-platform NFC library rather than adding it to Toga itself. But let's leave this issue open at least until someone's had a chance to investigate what those libraries are.

mhsmith avatar Nov 19 '24 13:11 mhsmith

@mhsmith We're talking about relevant Python libraries only, right? Because I do not think there are any at the moment.

I could only find nfcpy but that seems to be a lower level implementation that provides drivers for some external devices. I don't think NFC reader devices in Android (and especially in iOS) phones are exposed in a way similar to external ones, so these probably cannot be added to nfcpy.

gy-mate avatar Nov 19 '24 14:11 gy-mate

@mhsmith We're talking about relevant Python libraries only, right? Because I do not think there are any at the moment.

In which case - sounds like a great opportunity to write one :-)

But seriously - the core point is that this may not need to be a feature of Toga. Some hardware (e.g., the camera API) involves a GUI component, which means some interaction with Toga is required. However, if an API can be implemented independent of a GUI representation, then there's no need for it to be part of Toga's core API. NFC and Bluetooth support are two areas where that is definitely the case - you're reading data over the air; how that data is displayed is independent of how the data is read.

The only place this gets complicated is in the choice of bridging layer - an implementation for iOS that uses Rubicon as the ObjC bridging layer will really only be compatible with the BeeWare ecosystem, and not as useful for Kivy (at least, not without duplicating the bridge layer, and dealing with having 2 representations of ObjC objects). But a togax-nfc library that provides a third-party, Toga-integrated NFC capability should be entirely possible. I'd even be open to the idea of extending Toga's core API to provide extension points for hardware, similar to what has been suggested for widgets in #2928.

freakboy3742 avatar Nov 19 '24 23:11 freakboy3742

It seems that all the APIs suggested above is like very low-level NFC stuff. I wonder if implementation of applications of NFC in Toga is not unwarranted -- e.g. a Wallet popup view for iPhones.

johnzhou721 avatar Oct 03 '25 02:10 johnzhou721