There's a LA service in my app that uses TouchID pretty much as usual. The problem is that I want to change what is written on the alert that shows up when touchId authentication is prompted. First it shows what I declare in reason string, than if auth fails, it only changes title to 'Repeat', but body stays the same.
Is there any chance to change the alert's body for a different message when auth fails? I tried changing reason string but no effect.
This project is created using Xamarin, but Objective-C/Swift code is also acceptable. Thanks in advance!
UPD: here's my code:
if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError))
{
var myReason = new NSString("Use your finger to authenticate");
replyHandler = new LAContextReplyHandler((success, error) =>
{
InvokeOnMainThread(() =>
{
if (success)
{
Login();
}
else
{
myReason = new NSString("Nope try again");
switch ((long)error.Code)
{
case (long)LAStatus.TouchIDLockout: // 5 times wrong, TouchID is locked system-wide
{
var alert = new UIAlertView("Sorry", "Exceeded and blocked message", null, "OK");
alert.Show();
touchIdButton.Hidden = true;
}
break;
case (long)LAStatus.AuthenticationFailed: // 3 times wrong
{
var alert = new UIAlertView("Sorry", "Exceeded message", null, "OK");
alert.Show();
touchIdButton.Hidden = true;
}
break;
case (long)LAStatus.UserFallback: //Enter Passcode
//no UserFallback for now
break;
}
}
});
});
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler);
No. There is no API for changing the Reason in between the auth process.
See https://developer.apple.com/documentation/localauthentication/lacontext/1514176-evaluatepolicy
This means: What you are trying is not intended by Apple. The reason for requesting the auth stays the same independent from the failed try count. In other words: Your reason for requesting hasn't change after the first failed attempt.
Advertisement section
If you are interested in a cross platform solution for fingerprint auth, have a look at my plugin :) https://github.com/smstuebe/xamarin-fingerprint