Nuget 패키지 관리에서 Plugin.Fingerprint 를 설치합니다.
MainPage.xaml.cs 에서 지문 인증 코드를 아래와 같이 추가합니다.
using Plugin.Fingerprint;
using Plugin.Fingerprint.Abstractions;
namespace Maui.BiometricTest
{
public partial class MainPage : ContentPage
{
public MainPage(IFingerprint fingerprint)
{
InitializeComponent();
}
private async void OnClicked(object sender, EventArgs e)
{
var request = new AuthenticationRequestConfiguration("지문인증", "지문을 인식해주세요.");
var result = await CrossFingerprint.Current.AuthenticateAsync(request);
if (result.Authenticated)
{
await DisplayAlert("지문인식 성공!", "접근가능", "OK");
}
else
{
await DisplayAlert("지문인식 실패!", "접근불가", "OK");
}
}
}
}
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="MauiApp5.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ScrollView>
<VerticalStackLayout Padding="30,0" Spacing="25">
<Label
SemanticProperties.HeadingLevel="Level1"
Style="{StaticResource Headline}"
Text="Fingerprint" />
<Button
Clicked="OnClicked"
HorizontalOptions="Fill"
SemanticProperties.Hint="Counts the number of times you click"
Text="Fingerprint" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
MauiProgram.cs 에 아래 코드를 추가합니다.
builder.Services.AddSingleton<MainPage>();
builder.Services.AddSingleton(typeof(IFingerprint), CrossFingerprint.Current);
using Plugin.Fingerprint;
using Plugin.Fingerprint.Abstractions;
namespace Maui.BiometricTest
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
builder.Services.AddSingleton<MainPage>();
builder.Services.AddSingleton(typeof(IFingerprint), CrossFingerprint.Current);
return builder.Build();
}
}
}
Platforms > Android > MainActivity.cs 에 OnCreate override 메서드를 추가합니다.
using Android.App;
using Android.Content.PM;
using Android.OS;
using Plugin.Fingerprint;
namespace Maui.BiometricTest
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
CrossFingerprint.SetCurrentActivityResolver(() => this);
}
}
}
Platforms > Android > AndroidManifest.xml 에 권한을 추가합니다.
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
</manifest>
결과 (지문 인식 부분은 보안으로 검게 보여집니다.)
참고
https://github.com/smstuebe/xamarin-fingerprint
.NET MAUI 간단한 Login 화면 만들기 (0) | 2024.05.02 |
---|---|
.NET MAUI Gallery 사진 가져오기 (0) | 2024.04.28 |
.NET MAUI Bottom Popup 표시하기 (0) | 2024.04.26 |
.NET MAUI MVVM 기본 처리 (0) | 2024.04.26 |
.NET MAUI xaml 단에서 x:DataType 과 BindingContext 의 차이점 (0) | 2024.04.26 |