I am growing a Flutter app that repeatedly reads NFC tags for attendance utilizing the flutter_nfc_kit bundle. The studying loop works superb on Android and principally superb on iOS, however on iOS gadgets I randomly get these exceptions after each learn:
PlatformException(500, Generic NFC Error, Session invalidated unexpectedly, null)
PlatformException(409, SessionCanceled, Session invalidated by person, null)
nfc studying loop inside a way :
void startNfcForAttendance({required BuildContext context}) async {
strive {
bool isAvailable =
await FlutterNfcKit.nfcAvailability == NFCAvailability.accessible;
if (!isAvailable) {
AppUtils.showToast(
message: "NFC not accessible for this machine",
backgroundColor: AppColors.errorToastColor,
textColor: AppColors.toastTextColor,
);
return;
}
strive {
await FlutterNfcKit.end();
} catch (e) {
log("$e");
}
if (_isNfcOn) {
log("message");
stopNfc();
return;
}
_isNfcOn = true;
notifyListeners();
whereas (_isNfcOn) {
strive {
last tag = await FlutterNfcKit.ballot(
readIso14443A: true,
readIso15693: true,
readIso14443B: true,
readIso18092: true,
timeout: const Length(seconds: 15),
);
String finalNFCValue = BigInt.parse(tag.id, radix: 16).toString();
await FlutterNfcKit.end();
if (Platform.isIOS) {
await Future.delayed(const Length(seconds: 2));
}
if (!context.mounted) {
return;
}
await markCardAttendance(cardValue: finalNFCValue);
} on PlatformException catch (e) {
if (Platform.isAndroid) {
if (e.code == "500") {
AppUtils.showToast(
message: "Please Restart Your App",
backgroundColor: AppColors.errorToastColor,
textColor: AppColors.toastTextColor,
);
}
}
if (e.code == "409" || e.code == "408") {
stopNfc();
}
} catch (e) {
await FlutterNfcKit.end();
await Future.delayed(const Length(milliseconds: 500));
}
}
} catch (e) {
AppUtils.showToast(
message: "NFC just isn't supported on this machine.",
backgroundColor: AppColors.errorToastColor,
textColor: AppColors.toastTextColor,
);
}
}
cease methodology :
void stopNfc() async {
_isNfcOn = false;
notifyListeners();
strive {
await FlutterNfcKit.end();
} catch (_) {}
}
How can I cease or deal with the random PlatformException(500)
and PlatformException(409)
errors on iOS when studying NFC tags repeatedly?
Is there a greater strategy to do steady NFC studying in Flutter on iOS due to its limits?