Cannot Run NFC in IOS
mahirandigital opened this issue · 6 comments
i got this message
XPC Error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.nfcd.service.corenfc was invalidated from this process." UserInfo={NSDebugDescription=The connection to service named com.apple.nfcd.service.corenfc was invalidated from this process.}
how to solve it?
im running into the same issue now.
does anysone solve this problem ?
does anysone solve this problem ?
I ended up using https://pub.dev/packages/flutter_nfc_kit
this works for both iOS and Android
does anysone solve this problem ?
I ended up using https://pub.dev/packages/flutter_nfc_kit
this works for both iOS and Android
I use this package too, but still get error CoreNFC like this
XPC Error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.nfcd.service.corenfc was invalidated from this process." UserInfo={NSDebugDescription=The connection to service named com.apple.nfcd.service.corenfc was invalidated from this process.}
Do you edit your appsDelegate.swift file for the nfc part?
can you show your setup and info.plist file for the nfc part?
Hi, I just found out the trick or how to solve.
before show the trick, this is my code
@override
void initState() {
super.initState();
_registerNFC();
}
void _registerNFC() async {
NfcManager.instance.startSession(
pollingOptions: {
NfcPollingOption.iso14443,
NfcPollingOption.iso15693,
NfcPollingOption.iso18092,
},
onDiscovered: (NfcTag tag) async {
print(tag.toString());
String mytag = "";
if (tag.data.containsKey("mifareclassic")) {
mytag = tag.data["mifareclassic"]["identifier"]
.map((e) => e.toRadixString(16).padLeft(2, '0'))
.join('')
.toString()
.toUpperCase();
print("classic");
} else if (tag.data.containsKey("mifareultralight")) {
mytag = tag.data["mifareultralight"]["identifier"]
.map((e) => e.toRadixString(16).padLeft(2, '0'))
.join('')
.toString()
.toUpperCase();
print("ultralight");
} else if (tag.data.containsKey("mifareplus")) {
mytag = tag.data["mifareplus"]["identifier"]
.map((e) => e.toRadixString(16).padLeft(2, '0'))
.join('')
.toString()
.toUpperCase();
print("plus");
} else if (tag.data.containsKey("mifaredesfire")) {
mytag = tag.data["mifaredesfire"]["identifier"]
.map((e) => e.toRadixString(16).padLeft(2, '0'))
.join('')
.toString()
.toUpperCase();
print("des fire");
} else {
mytag = 'unknown type card';
}
// var lastID = mytag[mytag.length - 1];
result.value = mytag;
uid = result.value;
NfcManager.instance.stopSession();
print("close session");
_updateNFC();
try {
// await ndef.write(message);
result.value = 'Success to "Ndef Write"';
NfcManager.instance.stopSession();
//_ndefWriteLock(); jangan letak kalau tak nnt tak boleh unlock balik
} catch (e) {
result.value = e;
NfcManager.instance
.stopSession(errorMessage: result.value.toString());
return;
}
});
}
void _updateNFC() {
if (uid != 'unknown type card') {
Navigator.pop(context, uid);
} else {
CustomDialog.show(context,
isDissmissable: false,
title: "Unknown NFC tag",
description:
"Please use another type. Type allowed: [MifareClassic] [MifareUltralight] [MifareDesFire]",
btnOkText: "I Understand", btnOkOnPress: () {
Navigator.pop(context);
print("open session");
_registerNFC();
});
}
}
info.plist file
<key>NFCReaderUsageDescription</key>
<string>to scan the NFC Tag on the fire extinguisher</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>nfc</string>
</array>
<key>com.apple.developer.nfc.readersession.felica.systemcodes</key>
<array>
<string>0003</string>
<string>04D1</string>
<string>8008</string>
<string>80DE</string>
<string>865E</string>
<string>8592</string>
<string>8B5D</string>
<string>8FC1</string>
<string>FE00</string>
</array>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>TAG</string>
<string>NDEF</string>
</array>
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
<string>A0000002310100000000000000000000</string>
<string>A0000002310200000000000000000000</string>
<string>A0000002480300000000000000000000</string>
... [the rest of the string]
</array>
open in xcode. Under the sections targets. Choose your targets > signing and capabilities > + capability
add "Near Field communication tag reading"
Close xcode. do run pod install.
before run, please restart your physical iphone. after it just run either in the xcode or flutter run in the vscode
thanks you it work for me after a restart