diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 5dc4427b7..c75466c85 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -28,6 +28,7 @@ namespace Bit.iOS public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate { private GaiCompletionHandler _dispatchHandler = null; + private NFCNdefReaderSession _nfcSession = null; private ILockService _lockService; private IDeviceInfoService _deviceInfoService; private iOSPushNotificationHandler _pushHandler = null; @@ -117,16 +118,25 @@ namespace Bit.iOS return; } - var del = new NFCReaderDelegate((success, message) => + if(listen) { - Debug.WriteLine((success ? "SUCCESS! " : "ERROR! ") + message); - if(success) + var del = new NFCReaderDelegate((success, message) => { - MessagingCenter.Send(Xamarin.Forms.Application.Current, "GotYubiKeyOTP", message); - } - }); - var session = new NFCNdefReaderSession(del, null, true); - session.BeginSession(); + Debug.WriteLine((success ? "SUCCESS! " : "ERROR! ") + message); + if(success) + { + MessagingCenter.Send(Xamarin.Forms.Application.Current, "GotYubiKeyOTP", message); + } + }); + + _nfcSession = new NFCNdefReaderSession(del, null, true); + _nfcSession.BeginSession(); + } + else + { + _nfcSession?.InvalidateSession(); + _nfcSession = null; + } }); UIApplication.SharedApplication.StatusBarHidden = false; diff --git a/src/iOS/NFCReaderDelegate.cs b/src/iOS/NFCReaderDelegate.cs index bdd076d4d..eac4e4296 100644 --- a/src/iOS/NFCReaderDelegate.cs +++ b/src/iOS/NFCReaderDelegate.cs @@ -35,10 +35,12 @@ namespace Bit.iOS foreach(var result in results) { Debug.WriteLine("READ TAG: " + result); - if(_otpPattern.IsMatch(result)) + var matches = _otpPattern.Matches(result); + if(matches.Count > 0 && matches[0].Groups.Count > 1) { - Debug.WriteLine("TAG IS MATCH: " + result); - _callback.Invoke(true, result); + var otp = matches[0].Groups[1].ToString(); + Debug.WriteLine("TAG IS MATCH: " + otp); + _callback.Invoke(true, otp); return; } }