Comments (8)
You probably need to unsubscribe and stop listening in the main thread like this:
Device.BeginInvokeOnMainThread(() =>
{
CrossNFC.Current.OnMessageReceived -= Current_OnMessageReceived;
CrossNFC.Current.StopListening();
});
from plugin.nfc.
You probably need to unsubscribe and stop listening in the main thread like this:
Device.BeginInvokeOnMainThread(() => { CrossNFC.Current.OnMessageReceived -= Current_OnMessageReceived; CrossNFC.Current.StopListening(); });
It worked. Thanks
from plugin.nfc.
instead of stop listening directly in Current_OnMessageReceived, i call it in another task not waited
private async void Current_OnMessageReceived(ITagInfo tagInfo)
{
// do stuff
await Task.Run(() => StopListening()).ConfigureAwait(false);
}
private async Task StopListening()
{
try
{
MainThread.BeginInvokeOnMainThread(() =>
{
CrossNFC.Current.StopListening();
CrossNFC.Current.OnMessageReceived -= Current_OnMessageReceived;
});
}
catch (Exception ex)
{
}
}
All this code is in a service and works for me on android and Maui (but I don't understand the underlying mechanism that makes it work)
Hope it can help someone
from plugin.nfc.
I added the above code at the end of the 'Current_OnMessageReceived' event handler and I'm still getting the error: You must disable foreground dispatching while your activity is still resumed
from plugin.nfc.
I added the above code at the end of the 'Current_OnMessageReceived' event handler and I'm still getting the error: You must disable foreground dispatching while your activity is still resumed
check if your page is => var page = new navigationpage(new scanpage());
and not var page = new scanpage(); (this didn't work for me)
from plugin.nfc.
This solution worked for me too. @pvanroos were you able to figure out your issue?
from plugin.nfc.
Yes, this helped. I make sure that events are subscribed and unsubscribed cleanly when loading a page or exiting a page where scanning is supposed to happen too.
Also, (off topic), I still wish I knew what causes the 'Stack Error' message on iOS. Once in a while, my users will see this message when attempting to scan an NFC tag. I think it's caused when they don't hold the phone still to allow the data transfer to execute cleanly. I wish we could hook an event handler into this error and handle it gracefully.
from plugin.nfc.
I added the above code at the end of the 'Current_OnMessageReceived' event handler and I'm still getting the error: You must disable foreground dispatching while your activity is still resumed
check if your page is => var page = new navigationpage(new scanpage()); and not var page = new scanpage(); (this didn't work for me)
scan worked on my homepage but not certain pages, however it worked on a page which used
"await Navigation.PushAsync(new pageName());" but now that i've changed my way to navigate , it works on every pages.
do we know why this way works and not the other?
from plugin.nfc.
Related Issues (20)
- Support for Waveshare ePaper Displays
- Native MiFare Commands
- How to solve Tag is not NDEF-compliant? HOT 2
- Stack Error during NFC scan HOT 1
- iOS 4099 error when BeginListening
- Scanning pasports and ID cards HOT 1
- Unable to build iOS for simulator using Xcode 14.3 and Xamarin.iOS 16.4.0.6 HOT 1
- Issue with NFC Tag detection in iOS - MAUI
- While using Navigation in MAUI on Android NFC tag is not scanned HOT 4
- Questions showing custom UI messages
- Write Tag Android got exception: Tag IO Error HOT 2
- IOS / Library not working after published to AppStore Connect / Testflight HOT 2
- working on formatting HOT 3
- Android NFC Read times slow
- [NOT A ISSUE] Question: AFI
- Using old ISO 15693 non NDEF cards HOT 1
- Though the device supports NFC, NFC is not available HOT 1
- CrossNFC.Current.StartListening() on Content Page load not working - .NET Maui Android App.
- Write VCARD data HOT 1
- Apple App Store submission fails validation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plugin.nfc.