HomeiOS Developmentandroid - The way to deal with random NFC session errors (500...

android – The way to deal with random NFC session errors (500 & 409) in Flutter iOS throughout steady NFC tag studying?


I am creating a Flutter app that constantly reads NFC tags for attendance utilizing the flutter_nfc_kit bundle. The studying loop works advantageous on Android and principally advantageous on iOS, however on iOS units 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 {
  attempt {
    bool isAvailable =
        await FlutterNfcKit.nfcAvailability == NFCAvailability.out there;

    if (!isAvailable) {
      AppUtils.showToast(
        message: "NFC not out there for this system",
        backgroundColor: AppColors.errorToastColor,
        textColor: AppColors.toastTextColor,
      );
      return;
    }

    attempt {
      await FlutterNfcKit.end();
    } catch (e) {
      log("$e");
    }

    if (_isNfcOn) {
      log("message");
      stopNfc();
      return;
    }

    _isNfcOn = true;
    notifyListeners();

    whereas (_isNfcOn) {
      attempt {
        ultimate 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 shouldn't be supported on this system.",
      backgroundColor: AppColors.errorToastColor,
      textColor: AppColors.toastTextColor,
    );
  }
}

cease methodology :

  void stopNfc() async {
    _isNfcOn = false;
    notifyListeners();
    attempt {
      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 constantly?

Is there a greater option to do steady NFC studying in Flutter on iOS due to its limits?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments