Closed sajadghawami closed 7 months ago
Hi! I faced the same issue and after move NfcManager.start()
into initalizeBackgroundTag()
everything work as expected.
Hope this will work to you
hey!
thank you for your reply. I also tried it like the following, but unfortunately that did not work:
import React from "react";
import NfcManager, { NfcEvents } from "react-native-nfc-manager";
const useNFCTest = () => {
const onBackgroundTag = async (tag: any) => {
console.log("onBackgroundTag", tag);
};
React.useEffect(() => {
const initalizeBackgroundTag = async () => {
// changed
await NfcManager.start();
const bgTag = await NfcManager.getBackgroundTag();
onBackgroundTag(bgTag);
// listen to other background tags after the app launched
NfcManager.setEventListener(
NfcEvents.DiscoverBackgroundTag,
onBackgroundTag
);
};
initalizeBackgroundTag();
}, []);
};
export default useNFCTest;
sorry! I forgot i also downgraded to "react-native-nfc-manager": "3.13.5"
Here are my source:
const [isEnable, setIsEnable] = useState(false);
const [message, setMessage] = useState<any>();
async function initNfc() {
try {
const supported = await NfcManager.isSupported();
if (supported) {
await NfcManager.start();
}
const getEnable = await NfcManager.isEnabled()
setIsEnable(getEnable)
const bgTag: TagEvent | null = await NfcManager.getBackgroundTag()
if (bgTag) {
const msg = Ndef.text.decodePayload(new Uint8Array(bgTag.ndefMessage[1].payload))
setMessage(msg)
}
} catch (error) { }
}
useEffect(() => {
initNfc()
}, [])
@phuocnh01
Thank you for clarifying!
Are you using the eventListener
somewhere:
NfcManager.setEventListener(
NfcEvents.DiscoverBackgroundTag,
onBackgroundTag
);
Because reading the nfc and then opening the app does work, but the background listener seems not to work... So iOS is actually showing the toast/popup that a nfc chip has been read, but in my application it will not be logged or triggered
hey @whitedogg13,
sorry for tagging you directly, but i am not able to fix this... not sure if this is a bug or my implementation.
thank you!
@sajadghawami did you make any progress with this?
@wordisthebird
unfortunately not
@wordisthebird
unfortunately not
no worries :) let me know if you do!
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
Hey there,
i wrote the following hook:
Here is what happens:
onBackgroundTag null
on startup (which is fine, since i didn't try with a tag)Environment:
react-native-nfc-manager@3.14.6
I also checked react-native-nfc-rewriter how it is implemented (here) but could not find a proper difference.
My questions
Thank you.