728x90

Visual Studio 2022 preview 17.3.0 실행
.NET MAUI 앱(미리보기) 로 프로젝트 만들기

Nuget 패키지 관리에서 시험판 포함 체크후 Plugin.Fingerprint 3.0.0-beta.1 설치

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");
            }
        }
    }
}

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 코드 추가

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);
        }
    }
}

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://www.youtube.com/shorts/bDWoIP8PHF0


소스
https://github.com/kei-soft/KJunBlog/tree/master/Maui.BiometricTest

728x90
Posted by kjun.kr
,