我尝试使用包
nfc_manager (nfc_manager: ^3.2.0)
扫描nfc标签。在 Android 中,一切顺利,但在 iOS 中,我只准备好动画进行扫描,但没有找到任何设备。
我在 info.plist 中尝试了很多值,我也尝试了所有文件:
https://github.com/okadan/nfc-manager/blob/master/ios/Runner/Info.plist
(来自包中的示例应用程序)。
我也尝试过
pollingOptions: {NfcPollingOption.iso14443, NfcPollingOption.iso15693}
我已打开 NFC 功能。
我的 fvm flutter 医生来了:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.11, on macOS 13.3.1 22E772610a darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.77.1)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 1 category.
这是我的小部件的一部分:
class NfcEnableWidget extends StatefulWidget {
final BuildContext contextParent;
const NfcEnableWidget({Key? key, required this.contextParent})
: super(key: key);
@override
_NfcEnableWidgetState createState() => _NfcEnableWidgetState();
}
class _NfcEnableWidgetState extends State<NfcEnableWidget> {
@override
void initState() {
super.initState();
NfcManager.instance.startSession(
// Here. NOTE: all options are specified by default.
//pollingOptions: {NfcPollingOption.iso14443, NfcPollingOption.iso15693},
onDiscovered: (tag) async {
// Do something with the valid tag data
final result = await widget.contextParent
.read<TagOnBoardingCubit>()
.checkNfcCode(tag);
if (result != null) {
ScaffoldMessenger.of(widget.contextParent).showSnackBar(
SnackBar(
content: Text(result),
),
);
}
},
);
}
过去几周我正在努力解决这个问题。
您的 iOS 版本是什么?并非所有 iPhone 都支持 NFC。
手机必须是iOS 13或更高版本且iPhone 6以上的iPhone。
阅读:https://developer.apple.com/design/ human-interface-guidelines/nfc