Тем не менее, вызов все еще не запускается на iOS, даже если все работает. Появляется приглашение сканирования NFC, указывая на то, что сеанс запускается правильно. Тем не менее, тег не читается, и вызов (NXP NTAG213)
Моя цель - прочитать обратный вызов.
Код: Выделить всё
void startNfc({required BuildContext context}) async {
try {
bool isAvailable = await NfcManager.instance.isAvailable();
if (!isAvailable) {
log("NFC not available");
AppUtils.showToast(
message: "NFC not available for this device",
backgroundColor: AppColors.errorToastColor,
textColor: AppColors.toastTextColor,
);
return;
}
try {
log("Stopping any existing NFC session (if any)");
await NfcManager.instance.stopSession();
} catch (e) {
log("No session to stop or error while stopping: $e");
}
if (_isNfcOn) {
_isNfcOn = false;
notifyListeners();
} else {
_isNfcOn = true;
notifyListeners();
NfcManager.instance.startSession(
pollingOptions: {
NfcPollingOption.iso14443,
NfcPollingOption.iso15693,
NfcPollingOption.iso18092,
},
alertMessageIos: "Hold the NFC-Tag on the upper back of your iPhone",
onSessionErrorIos: (p0) {
_isNfcOn = false;
notifyListeners();
log("Mesage${p0.message}");
},
onDiscovered: (NfcTag tag) async {
log("Tag Discoverd");
try {
if (!_isNfcReading) {
_isNfcReading = true;
num decodeValue = 0;
if (Platform.isIOS) {
log("iOS");
} else {
Uint8List? idBytes;
// 1️⃣ Most Mifare / ISO 14443-3A cards
final nfcA = NfcAAndroid.from(tag);
if (nfcA != null) {
idBytes = nfcA.tag.id;
}
// 2️⃣ (fallback) Some MifareClassic cards
if (idBytes == null) {
final mc = MifareClassicAndroid.from(tag);
idBytes = mc?.tag.id;
}
log(idBytes.toString());
final List encodedByte = idBytes!;
for (var i = 0; i < encodedByte.length; i++) {
log(encodedByte[i].toString());
decodeValue += encodedByte[i] * pow(256, i);
}
log(" ➡️ NFC TAG 🆔 : $decodeValue");
}
await Future.delayed(const Duration(milliseconds: 2000));
_isNfcReading = false;
log("📞 API CALL Done");
}
} catch (e) {
await NfcManager.instance.stopSession();
_isNfcOn = false;
notifyListeners();
log("Error while reading NFC CARD$e");
}
},
);
}
} catch (e) {
AppUtils.showToast(
message: "NFC is not supported on this device.",
backgroundColor: AppColors.errorToastColor,
textColor: AppColors.toastTextColor,
);
log("Session Error: $e");
}
}
< /code>
[b]Info.plist
Код: Выделить всё
NFCReaderUsageDescription
Allow access to Read tag
com.apple.developer.nfc.readersession.formats
TAG
com.apple.developer.nfc.readersession.felica.systemcodes
0003
04D1
8008
80DE
865E
8592
8B5D
8FC1
FE00
com.apple.developer.nfc.readersession.iso7816.select-identifiers
A0000002310100000000000000000000
A0000002310200000000000000000000
A0000002480300000000000000000000
A00000006510
.......
.......
A000000118454E
< /code>
[b]Runner.entitlements
Код: Выделить всё
com.apple.developer.nfc.readersession.formats
TAG
in xcode
Ошибки не отображаются в журналах, но в журналах, но не открыты>
Подробнее здесь: https://stackoverflow.com/questions/796 ... lutter-app