版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
【移動應(yīng)用開發(fā)技術(shù)】iOS指紋驗證TouchID怎么用
第一部分:調(diào)用原生服務(wù)實現(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,授權(quán)失敗");
//授權(quán)失敗
[[NSOperationQueue
mainQueue]
addOperationWithBlock:^{
//其他情況,切換主線程處理
}];
break;
}
}
}
}];
}else
{
//不支持指紋識別,LOG出錯誤詳情
switch
(error.code)
{
case
LAErrorTouchIDNotEnrolled:
{
NSLog(@"設(shè)備Touch
ID不可用,用戶未錄入");
break;
}
case
LAErrorPasscodeNotSet:
{
NSLog(@"系統(tǒng)未設(shè)置密碼");
break;
}
case
LAErrorTouchIDNotAvailable:
{
NSLog(@"設(shè)備Touch
ID不可用,例如未打開");
break;
}
default:
{
NSLog(@"系統(tǒng)未設(shè)置密碼");
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
//當(dāng)前設(shè)備不支持指紋識別
-
(void)WJTouchIDIsNotSupport;
//當(dāng)前軟件被掛起取消了授權(quán)(如突然來了電話,應(yīng)用進入前臺)
-
(void)WJTouchIDAuthorizeErrorAppCancel;
//取消TouchID驗證
(用戶點擊了取消)
-
(void)WJTouchIDAuthorizeErrorUserCancel;
//在TouchID對話框中點擊輸入密碼按鈕
-
(void)WJTouchIDAuthorizeErrorUserFallback;
//在驗證的TouchID的過程中被系統(tǒng)取消
例如突然來電話、按了Home鍵、鎖屏...
-
(void)WJTouchIDAuthorizeErrorSystemCancel;
//無法啟用TouchID,設(shè)備沒有設(shè)置密碼
-
(void)WJTouchIDAuthorizeErrorPasscodeNotSet;
//多次連續(xù)使用Touch
ID失敗,Touch
ID被鎖,需要用戶輸入密碼解鎖
-
(void
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 廣東松山職業(yè)技術(shù)學(xué)院《文獻檢索與利用》2023-2024學(xué)年第一學(xué)期期末試卷
- 廣東生態(tài)工程職業(yè)學(xué)院《海洋生物資源調(diào)查》2023-2024學(xué)年第一學(xué)期期末試卷
- 廣東青年職業(yè)學(xué)院《基礎(chǔ)醫(yī)學(xué)概論Ⅱ3(病理學(xué))》2023-2024學(xué)年第一學(xué)期期末試卷
- 七年級上冊《5.2.1 解一元一次方程 合并同類項》課件與作業(yè)
- 廣東南華工商職業(yè)學(xué)院《飛機裝配技術(shù)》2023-2024學(xué)年第一學(xué)期期末試卷
- 廣東嶺南職業(yè)技術(shù)學(xué)院《素描(1)》2023-2024學(xué)年第一學(xué)期期末試卷
- 會計年終工作總結(jié)
- 2025年人教版七年級數(shù)學(xué)寒假復(fù)習(xí) 專題01 有理數(shù)(6重點串講+15考點提升+過關(guān)檢測)
- 【全程復(fù)習(xí)方略】2020年高考化學(xué)課時提升作業(yè)(三十一)-11.1-脂肪烴(人教版-四川專供)
- 【狀元之路】2020-2021學(xué)年高中數(shù)學(xué)人教B版必修3雙基限時練12
- 二年級上冊《語文園地八》日積月累
- 2024年保護環(huán)境的建議書范文(33篇)
- 2024年中國PVC鞋底料市場調(diào)查研究報告
- 退休人員公益活動合作合同
- 四年級數(shù)學(xué)(四則混合運算帶括號)計算題專項練習(xí)與答案
- 2022年期貨從業(yè)資格《期貨基礎(chǔ)知識》考試題庫(含典型題)
- 浙江省湖州市2023-2024學(xué)年高二上學(xué)期期末調(diào)研測試數(shù)學(xué)試題 含解析
- 商業(yè)街價格策略與收益預(yù)測
- 浙江省杭州市蕭山區(qū)2023-2024學(xué)年高二上學(xué)期1月期末考試物理試題(含答案)
- 江西省九江市2023-2024學(xué)年七年級上學(xué)期語文期末試卷(含答案)
- 浙江省杭州市2023-2024學(xué)年六年級上學(xué)期期末科學(xué)試卷(含答案)1
評論
0/150
提交評論