简体   繁体   English

确保在 React Native 中关闭 NFC

[英]Make sure NFC is turned off in React Native

In my React Native app, one of the screens shows the QR code.在我的 React Native 应用程序中,其中一个屏幕显示 QR 码。 That QR code should be placed to the QR code reader, which has also NFC capabilities.该 QR 码应放置在具有 NFC 功能的 QR 码阅读器中。

My task is to make sure that the NFC is turned off.我的任务是确保 NFC 已关闭。 Yep, my app does not have any NFC features or capabilities.是的,我的应用程序没有任何 NFC 特性或功能。 No permissions are set in AndroidManifest or Info.plist. AndroidManifest 或 Info.plist 中未设置任何权限。

That is just a QR code provider (NS from the Netherlands) requirement to make sure the NFC is off.这只是 QR 码提供商(来自荷兰的 NS)的要求,以确保 NFC 已关闭。 How to make it?怎么做?

Is that possible that another app somehow uses NFC at this time?是否有可能此时另一个应用程序以某种方式使用 NFC?

Update:更新:

Generally, the issue is with Apple Pay and Google Pay.通常,问题在于 Apple Pay 和 Google Pay。 While trying to scan the QR code from the screen both payment applications are popped up, which prevents reading the QR code.尝试从屏幕扫描二维码时,会弹出两个支付应用程序,从而阻止读取二维码。

So the idea is just to disable those payment applications while using our app.所以这个想法只是在使用我们的应用程序时禁用这些支付应用程序。

related issue on Github https://github.com/revtel/react-native-nfc-manager/issues/455 Github https 上的相关问题://github.com/revtel/react-native-nfc-manager/issues/455

I had to use NFC capabilities in a RN app.我必须在 RN 应用程序中使用 NFC 功能。 This is the package I've used: https://github.com/revtel/react-native-nfc-manager .这是我用过的 package: https://github.com/revtel/react-native-nfc-manager The setup is simple on Android but can be tricky on iOS: https://github.com/revtel/react-native-nfc-manager/blob/main/setup.md Android 上的设置很简单,但在 iOS 上可能会很棘手: https://github.com/revtel/react-native-nfc-dmanager/blob/。

You have methods such as isEnabled(): Promise<boolean>;您有诸如isEnabled(): Promise<boolean>;类的方法or isSupported(): Promise<boolean>;isSupported(): Promise<boolean>; . . I believe they will be enough for you.我相信它们对你来说已经足够了。

Disclaimer:免责声明:
I never tried to use those functions to check that directly: I usually check for the changes in the state since I need to give out some warnings.我从未尝试使用这些函数直接检查:我通常检查 state 中的更改,因为我需要发出一些警告。

Also I don't simply check for on or off.此外,我不只是检查开或关。 I use something because I need to make sure the iPhone can use the NFC for read/write (and not just payments)我使用某些东西是因为我需要确保 iPhone 可以使用 NFC 进行读/写(而不仅仅是支付)

try {
    await NfcManager.isSupported(NfcTech.Iso15693IOS);
} catch (error) {
    // set state = off and unsupported

So the problem with Apple Pay and Google Pay is as follow:所以 Apple Pay 和 Google Pay 的问题如下:

  • try to scan the QR code on a mobile device尝试在移动设备上扫描二维码
  • Actual behavior: payment application is popped up实际行为:弹出支付应用
  • Expected behavior: QR stays on the screen预期行为:QR 停留在屏幕上

So the idea is just to disable those payment applications while using our app.所以这个想法只是在使用我们的应用程序时禁用这些支付应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM