■ IFingerprint 인터페이스의 AuthenticateAsync 메소드를 사용해 지문을 인증하는 방법을 보여준다. (ANDROID)
▶ Platforms/Android/AndroidManifest.xml
1 2 3 4 5 6 7 8 |
<?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.USE_BIOMETRIC" /> </manifest> |
▶ Platforms/Android/MainActivity.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
using Android.App; using Android.Content.PM; using Android.OS; using Plugin.Fingerprint; namespace TestProject; /// <summary> /// 메인 액티비티 /// </summary> [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] public class MainActivity : MauiAppCompatActivity { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 생성시 처리하기 - OnCreate(savedInstanceState) /// <summary> /// 생성시 처리하기 /// </summary> /// <param name="savedInstanceState">저장 인스턴스 상태</param> protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); CrossFingerprint.SetCurrentActivityResolver(() => this); } #endregion } |
▶ MauiProgram.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
using Plugin.Fingerprint; using Plugin.Fingerprint.Abstractions; namespace TestProject; /// <summary> /// MAUI 프로그램 /// </summary> public static class MauiProgram { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region MAUI 앱 생성하기 - CreateMauiApp() /// <summary> /// MAUI 앱 생성하기 /// </summary> /// <returns>MAUI 앱</returns> 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(typeof(IFingerprint), CrossFingerprint.Current); return builder.Build(); } #endregion } |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Button x:Name="authenticationButton" HorizontalOptions="Center" VerticalOptions="Center" Text="지문 인증" /> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using Plugin.Fingerprint; using Plugin.Fingerprint.Abstractions; namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.authenticationButton.Clicked += authenticationButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 지문 인증 버튼 클릭시 처리하기 - authenticationButton_Clicked(sender, e) /// <summary> /// 지문 인증 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private async void authenticationButton_Clicked(object sender, EventArgs e) { AuthenticationRequestConfiguration authenticationRequestConfiguration = new AuthenticationRequestConfiguration("사용자 인증", "지문을 인식해 주세요."); FingerprintAuthenticationResult result = await CrossFingerprint.Current.AuthenticateAsync(authenticationRequestConfiguration); if(result.Authenticated) { await DisplayAlert("INFORMATION", "지문 인식을 성공했습니다.", "확인"); } else { await DisplayAlert("INFORMATION", "지문 인식을 실패했습니다.", "확인"); } } #endregion } |