Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on IOS #207

Open
computerfriendlog2 opened this issue Oct 1, 2024 · 0 comments
Open

Not working on IOS #207

computerfriendlog2 opened this issue Oct 1, 2024 · 0 comments

Comments

@computerfriendlog2
Copy link

My Code
void _tagRead() async {
print('testing -------------> read tag');
isWritingNFC=true;
setState((){});

bool isAvailable = await NfcManager.instance.isAvailable();

print('nfc  is    available ...... ${isAvailable}');

//try{
  NfcManager.instance.startSession(
      onDiscovered: (NfcTag tag) async {
    print('nfc  here1...... $tag');
    print('nfc  here2...... ${tag.data}');
    print('nfc  here3...... ${tag.data['id']}');
    print('nfc  here4...... ${tag.handle}');
    String? hexId;
    try {
      // Attempt to retrieve the ID from various potential sources
      if (tag.data.containsKey('nfca')) {
        final id = tag.data['nfca']['identifier'];
        hexId = _convertIdToHex(id);
      } else if (tag.data.containsKey('nfcb')) {
        final id = tag.data['nfcb']['identifier'];
        hexId = _convertIdToHex(id);
      } else if (tag.data.containsKey('iso7816')) {
        final id = tag.data['iso7816']['identifier'];
        hexId = _convertIdToHex(id);
      } else if (tag.data.containsKey('iso15693')) {
        final id = tag.data['iso15693']['identifier'];
        hexId = _convertIdToHex(id);
      } else if (tag.data.containsKey('ndef')) {
        final id = tag.data['ndef']['identifier'];
        hexId = _convertIdToHex(id);
      }

      // Display the ID or a message if ID is null
      setState(() {
        print('NFC card id is here----> ${hexId!.replaceAll(':', '')}');
      });
    } catch (e) {
      print('NFC card id getting error here----> ${e.toString()}');
    }

    /// ////////////////////////////////////////////
    Ndef? ndef = Ndef.from(tag);
    print('nfc tag is here...... ${ndef!.cachedMessage!.records.first.payload}');
    String readTag = utf8.decode(ndef.cachedMessage!.records.first.payload);
    //String serialKey='';
    print('Decoded content: $readTag');
    if(readTag.contains('---') && readTag.contains('...') ) {

      // if(readTag.contains('+++') ) {
      //   print('serialKey content: ${readTag.split('...')[1]}   ===> ${readTag.split('...')[1].split('+++').first}');
      //   serialKey=readTag.split('...')[1].split('+++').first;
      //   print('Decoded serialKey :${serialKey} ');
      // }
      readTag= readTag.split('---')[1].split('...').first;
    }
    Helper.msgDialog(context, "NFC TAG is '$readTag'.", () {// and serial key is $serialKey
      Navigator.of(context).pop();
    },   );
    print('nfc tag is here...... ${ndef.maxSize}');
    isWritingNFC=false;
    setState((){});
  },
    onError: (d) async {
        print('nfc error is 1 here-----> ${d.type.toString()}');
        print('nfc error is 2 here-----> ${d.type.name}');
        print('nfc error is 3 here-----> ${d.details.toString()}');
        print('nfc error is 4 here-----> ${d.message}');
        print('nfc error is 4 here-----> ${d.toString()}');
      //return Future.value();
    },
    alertMessage: 'test alert'
  );
// } catch(e) {
//   print('testing -------------> ${e.toString()}');
//   Helper.toast('Please try again');
//   isWritingNFC=false;
//   setState((){});
// }

}

I used other dependency its working means there is no any configuration issue.

But in this case its not working on IOS, either android is working fine.

I'm getting output
flutter: nfc is available ...... true
flutter: nfc error is 1 here-----> NfcErrorType.unknown
flutter: nfc error is 2 here-----> unknown
flutter: nfc error is 3 here-----> null
flutter: nfc error is 4 here-----> Missing required entitlement
flutter: nfc error is 4 here-----> Instance of 'NfcError'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant