BEMUTATÓRA kész.
This commit is contained in:
@@ -36,6 +36,11 @@ public partial class NFCWaiter : ContentPage
|
||||
}
|
||||
|
||||
}
|
||||
protected override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
}
|
||||
|
||||
async Task AutoStartAsync()
|
||||
{
|
||||
// Some delay to prevent Java.Lang.IllegalStateException "Foreground dispatch can only be enabled when your activity is resumed" on Android
|
||||
@@ -47,6 +52,7 @@ public partial class NFCWaiter : ContentPage
|
||||
|
||||
await BeginListening();
|
||||
}
|
||||
|
||||
async Task BeginListening()
|
||||
{
|
||||
try
|
||||
@@ -62,16 +68,14 @@ public partial class NFCWaiter : ContentPage
|
||||
//await ShowAlert(ex.Message);
|
||||
}
|
||||
}
|
||||
async Task EndListening()
|
||||
async Task StopListening()
|
||||
{
|
||||
try
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
UnsubscribeEvents();
|
||||
CrossNFC.Current.StopPublishing();
|
||||
CrossNFC.Current.StopListening();
|
||||
|
||||
UnsubscribeEvents();
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -79,6 +83,7 @@ public partial class NFCWaiter : ContentPage
|
||||
//await ShowAlert(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
void SubscribeEvents()
|
||||
{
|
||||
if (_eventsAlreadySubscribed)
|
||||
@@ -86,18 +91,21 @@ public partial class NFCWaiter : ContentPage
|
||||
|
||||
_eventsAlreadySubscribed = true;
|
||||
|
||||
CrossNFC.Current.OnMessageReceived += Current_OnMessageReceived_NFCData;
|
||||
CrossNFC.Current.OnMessageReceived += OnMessageReceived_NFCData;
|
||||
|
||||
|
||||
}
|
||||
void UnsubscribeEvents()
|
||||
{
|
||||
CrossNFC.Current.OnMessageReceived -= Current_OnMessageReceived_NFCData;
|
||||
CrossNFC.Current.OnMessageReceived -= OnMessageReceived_NFCData;
|
||||
_eventsAlreadySubscribed = false;
|
||||
}
|
||||
async void Current_OnMessageReceived_NFCData(ITagInfo tagInfo)
|
||||
async void OnMessageReceived_NFCData(ITagInfo tagInfo)
|
||||
{
|
||||
_onReceiveing = true;
|
||||
|
||||
|
||||
|
||||
if (tagInfo == null)
|
||||
{
|
||||
await ShowAlert("No tag found");
|
||||
@@ -109,9 +117,16 @@ public partial class NFCWaiter : ContentPage
|
||||
var identifier = tagInfo.Identifier;
|
||||
var serialNumber = NFCUtils.ByteArrayToHexString(identifier, ":");
|
||||
_taskCompletionSource.TrySetResult(serialNumber);
|
||||
await EndListening();
|
||||
await Navigation.PopAsync();
|
||||
_onReceiveing = false;
|
||||
|
||||
await Task.Delay(500);
|
||||
await StopListening();
|
||||
|
||||
await MainThread.InvokeOnMainThreadAsync(async () =>
|
||||
{
|
||||
await Navigation.PopModalAsync();
|
||||
//await Navigation.PopModalAsync();
|
||||
});
|
||||
}
|
||||
Task ShowAlert(string message, string title = null) => DisplayAlert(string.IsNullOrWhiteSpace(title) ? "NFC olvasás" : title, message, "OK");
|
||||
}
|
||||
Reference in New Issue
Block a user