版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
【移動應用開發(fā)技術】iOS指紋驗證TouchID怎么用
第一部分:調用原生服務實現(xiàn)指紋驗證/upload/information/20200623/126/122739.jpg/upload/information/20200623/126/122740.jpg/upload/information/20200623/126/122741.jpg#import
"AppDelegate.h"
#import
"ViewController.h"
@interface
AppDelegate
()
@end
@implementation
AppDelegate
-
(BOOL)application:(UIApplication
*)application
didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
//appdelegate
_window
=
[[UIWindow
alloc]initWithFrame:[UIScreen
mainScreen].bounds];
_window.backgroundColor
=
[UIColor
whiteColor];
[_window
makeKeyAndVisible];
ViewController
*vc
=
[[ViewController
alloc]init];
UINavigationController
*na
=
[[UINavigationController
alloc]initWithRootViewController:vc];
_window.rootViewController
=
na;
return
YES;
}第四步:實現(xiàn)指紋驗證
-canEvaluatePolicy:error:
//-(BOOL)canEvaluatePolicy:(LAPolicy)policy
error:(NSError
*
__autoreleasing
*)error
__attribute__((swift_error(none)));
-evaluatePolicy:localizedReason:reply:
//-
(void)evaluatePolicy:(LAPolicy)policy
localizedReason:(NSString
*)localizedReason
reply:(void(^)(BOOL
success,
NSError
*
__nullable
error))reply;-
(void)viewDidLoad
{
[super
viewDidLoad];
self.title
=
@"TouchIDSimpleDemoOne";
LAContext
*context
=
[[LAContext
alloc]init];
NSError
*error;
NSString
*result
=
@"需要你身份驗證呢";
if
([context
canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
error:&error])
{
[context
evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:result
reply:^(BOOL
success,
NSError
*error)
{
if
(success)
{
//驗證成功,主線程處理UI
//這個地方呢就是寫一些驗證成功之后需要做些什么事情的代碼。
NSLog(@"驗證成功");
}
else
{
//以下是一些驗證失敗的原因啥的
NSLog(@"%@",error.localizedDescription);
switch
(error.code)
{
case
LAErrorSystemCancel:
{
NSLog(@"切換到其他APP,系統(tǒng)取消驗證Touch
ID");
//切換到其他APP,系統(tǒng)取消驗證Touch
ID
break;
}
case
LAErrorUserCancel:
{
NSLog(@"用戶取消驗證Touch
ID");
//用戶取消驗證Touch
ID
break;
}
case
LAErrorUserFallback:
{
NSLog(@"用戶選擇輸入密碼");
[[NSOperationQueue
mainQueue]
addOperationWithBlock:^{
//用戶選擇其他驗證方式,切換主線程處理
}];
break;
}
default:
{
NSLog(@"LAErrorAuthenticationFailed,授權失敗");
//授權失敗
[[NSOperationQueue
mainQueue]
addOperationWithBlock:^{
//其他情況,切換主線程處理
}];
break;
}
}
}
}];
}else
{
//不支持指紋識別,LOG出錯誤詳情
switch
(error.code)
{
case
LAErrorTouchIDNotEnrolled:
{
NSLog(@"設備Touch
ID不可用,用戶未錄入");
break;
}
case
LAErrorPasscodeNotSet:
{
NSLog(@"系統(tǒng)未設置密碼");
break;
}
case
LAErrorTouchIDNotAvailable:
{
NSLog(@"設備Touch
ID不可用,例如未打開");
break;
}
default:
{
NSLog(@"系統(tǒng)未設置密碼");
break;
}
}
NSLog(@"%@",error.localizedDescription);
}
}//指紋驗證返回值
typedef
NS_ENUM(NSInteger,
LAError)
{
///
Authentication
was
not
successful,
because
user
failed
to
provide
valid
credentials.
LAErrorAuthenticationFailed
=
kLAErrorAuthenticationFailed,
///
Authentication
was
canceled
by
user
(e.g.
tapped
Cancel
button).
LAErrorUserCancel
=
kLAErrorUserCancel,
///
Authentication
was
canceled,
because
the
user
tapped
the
fallback
button
(Enter
Password).
LAErrorUserFallback
=
kLAErrorUserFallback,
///
Authentication
was
canceled
by
system
(e.g.
another
application
went
to
foreground).
LAErrorSystemCancel
=
kLAErrorSystemCancel,
///
Authentication
could
not
start,
because
passcode
is
not
set
on
the
device.
LAErrorPasscodeNotSet
=
kLAErrorPasscodeNotSet,
///
Authentication
could
not
start,
because
Touch
ID
is
not
available
on
the
device.
LAErrorTouchIDNotAvailable
=
kLAErrorTouchIDNotAvailable,
///
Authentication
could
not
start,
because
Touch
ID
has
no
enrolled
fingers.
LAErrorTouchIDNotEnrolled
=
kLAErrorTouchIDNotEnrolled,
///
Authentication
was
not
successful,
because
there
were
too
many
failed
Touch
ID
attempts
and
///
Touch
ID
is
now
locked.
Passcode
is
required
to
unlock
Touch
ID,
e.g.
evaluating
///
LAPolicyDeviceOwnerAuthenticationWithBiometrics
will
ask
for
passcode
as
a
prerequisite.
LAErrorTouchIDLockout
NS_ENUM_AVAILABLE(10_11,
9_0)
=
kLAErrorTouchIDLockout,
///
Authentication
was
canceled
by
application
(e.g.
invalidate
was
called
while
///
authentication
was
in
progress).
LAErrorAppCancel
NS_ENUM_AVAILABLE(10_11,
9_0)
=
kLAErrorAppCancel,
///
LAContext
passed
to
this
call
has
been
previously
invalidated.
LAErrorInvalidContext
NS_ENUM_AVAILABLE(10_11,
9_0)
=
kLAErrorInvalidContext
}
NS_ENUM_AVAILABLE(10_10,
8_0);第二部分:利用現(xiàn)有的第三方組件實現(xiàn)/upload/information/20200623/126/122742.jpg-
(void)viewDidLoad
{
[super
viewDidLoad];
//初始化
WJTouchID
*touchid
=
[[WJTouchID
alloc]init];
[touchid
startWJTouchIDWithMessage:WJNotice(@"自定義信息",
@"The
Custom
Message")
fallbackTitle:WJNotice(@"",
@"Fallback
Title")
delegate:self];
self.touchID
=
touchid;
}@required
//TouchID驗證成功
-
(void)WJTouchIDAuthorizeSuccess;
//TouchID驗證失敗
-
(void)WJTouchIDAuthorizeFailure;
@optional
//當前設備不支持指紋識別
-
(void)WJTouchIDIsNotSupport;
//當前軟件被掛起取消了授權(如突然來了電話,應用進入前臺)
-
(void)WJTouchIDAuthorizeErrorAppCancel;
//取消TouchID驗證
(用戶點擊了取消)
-
(void)WJTouchIDAuthorizeErrorUserCancel;
//在TouchID對話框中點擊輸入密碼按鈕
-
(void)WJTouchIDAuthorizeErrorUserFallback;
//在驗證的TouchID的過程中被系統(tǒng)取消
例如突然來電話、按了Home鍵、鎖屏...
-
(void)WJTouchIDAuthorizeErrorSystemCancel;
//無法啟用TouchID,設備沒有設置密碼
-
(void)WJTouchIDAuthorizeErrorPasscodeNotSet;
//多次連續(xù)使用Touch
ID失敗,Touch
ID被鎖,需要用戶輸入密碼解鎖
-
(void
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 旅游客服人員聘用合同
- 城中村租賃合同:服裝店租賃細則
- 廣告創(chuàng)意策劃師聘用合同
- 通訊設備銷售代表招聘合同
- 農莊租賃合同:農業(yè)種植基地
- 商業(yè)綜合體自來水安裝協(xié)議
- 鋁合金風力發(fā)電設備生產合同
- 可持續(xù)旅游合同管理辦法
- 電信工程腳手架施工合同范本
- 珠寶設計代理協(xié)議
- 2024年度石料供應框架協(xié)議
- 2024年度技術開發(fā)合同違約處理3篇
- 辦公家具無償租賃合同
- 臥式橢圓封頭儲罐液位體積對照表
- 《家庭安全用電培訓》課件
- 人教版數(shù)學一年級上冊 前后上下左右專項練習題(試題)
- 【初中道法】樹立正確的人生目標(課件)-2024-2025學年七年級道德與法治上冊(統(tǒng)編版2024)
- 全國自考社會經濟調查方法與應用真題
- 鋼結構施工方案編制指南
- 中醫(yī)婦科疾病的治療(完美版)課件
- 山東省青島市2024-2025學年七年級上學期11月期中英語試題
評論
0/150
提交評論