From f90c407fb68bf46561009a34e41a61fd2cb9bae3 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 24 May 2018 22:33:29 -0400 Subject: [PATCH] move nfc delegate to member of appdelegate class --- src/iOS/AppDelegate.cs | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 133f54722..5b1a666ae 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -33,6 +33,7 @@ namespace Bit.iOS private ILockService _lockService; private IDeviceInfoService _deviceInfoService; private iOSPushNotificationHandler _pushHandler = null; + private NFCReaderDelegate _nfcDelegate = null; public ISettings Settings { get; set; } @@ -48,6 +49,7 @@ namespace Bit.iOS _lockService = Resolver.Resolve(); _deviceInfoService = Resolver.Resolve(); _pushHandler = new iOSPushNotificationHandler(Resolver.Resolve()); + _nfcDelegate = new NFCReaderDelegate((success, message) => ProcessYubikey(success, message)); var appIdService = Resolver.Resolve(); var crashManagerDelegate = new HockeyAppCrashManagerDelegate( @@ -119,30 +121,15 @@ namespace Bit.iOS return; } + _nfcSession?.InvalidateSession(); + _nfcSession?.Dispose(); + _nfcSession = null; if(listen) { - _nfcSession?.InvalidateSession(); - _nfcSession?.Dispose(); - _nfcSession = null; - _nfcSession = new NFCNdefReaderSession(new NFCReaderDelegate((success, message) => - { - if(success) - { - Device.BeginInvokeOnMainThread(() => - { - MessagingCenter.Send(Xamarin.Forms.Application.Current, "GotYubiKeyOTP", message); - }); - } - }), null, true); + _nfcSession = new NFCNdefReaderSession(_nfcDelegate, null, true); _nfcSession.AlertMessage = AppResources.HoldYubikeyNearTop; _nfcSession.BeginSession(); } - else - { - _nfcSession?.InvalidateSession(); - _nfcSession?.Dispose(); - _nfcSession = null; - } }); UIApplication.SharedApplication.StatusBarHidden = false; @@ -362,5 +349,16 @@ namespace Bit.iOS Gai.SharedInstance.Dispatch(_dispatchHandler); } + + private void ProcessYubikey(bool success, string message) + { + if(success) + { + Device.BeginInvokeOnMainThread(() => + { + MessagingCenter.Send(Xamarin.Forms.Application.Current, "GotYubiKeyOTP", message); + }); + } + } } }