iOS8以后使用系统TouchID功能

2017年02月09日 iOS 27条评论 阅读3899次

iOS8以后,苹果公开了TouchID的验证功能,使得自己开发的APP能够更好更方便地保护用户信息及数据。

下面是使用TouchID验证的全部代码。


#import <LocalAuthentication/LocalAuthentication.h>
- (void)beginTouch {
    LAContext *context = [[LAContext alloc]init];
    NSError *err = nil;
    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&err]) {
        if (err) {
            NSLog(@"%@", err);
            return;
        }
        context.localizedFallbackTitle = @"使用密码";
        context.localizedCancelTitle= @"取消";
        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"现在按上指纹" reply:^(BOOL success, NSError * _Nullable error) {
            if (error) {
                NSLog(@"%@", error);
                switch (error.code) {
                    case LAErrorAuthenticationFailed:
                        NSLog(@"LAErrorAuthenticationFailed:连续三次指纹认证失败!");
                        break;
                    case LAErrorUserCancel:
                        NSLog(@"LAErrorUserCancel:用户已取消!");
                        break;
                    case LAErrorUserFallback:
                        NSLog(@"LAErrorUserFallback:用户选择使用Fallback的功能!");
                        break;
                    case LAErrorSystemCancel:
                        NSLog(@"LAErrorSystemCancel:TouchID对话框被系统取消,例如按下Home或者电源键进入后台!");
                        break;
                    case LAErrorPasscodeNotSet:
                        NSLog(@"LAErrorPasscodeNotSet:设备系统未设置密码!");
                        break;
                    case LAErrorTouchIDNotAvailable:
                        NSLog(@"LAErrorTouchIDNotAvailable:设备未设置Touch ID!");
                        break;
                    case LAErrorTouchIDNotEnrolled:
                        NSLog(@"LAErrorTouchIDNotEnrolled:用户未录入指纹!");
                        break;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
                    case LAErrorTouchIDLockout:
                        NSLog(@"LAErrorTouchIDLockout:Touch ID被锁,需要用户输入密码解锁!");
                        break;
                    case LAErrorAppCancel:
                        NSLog(@"LAErrorAppCancel:如突然来了电话,电话应用进入前台,APP被挂起啦!");
                        break;
                    case LAErrorInvalidContext:
                        NSLog(@"LAErrorInvalidContext:LAContext传递给这个调用之前已经失效!");
                        break;
#else
#endif
                    default:
                        break;
                }
                return;
            }
            if (success) {
                NSLog(@"指纹认证成功!");
            } else {
                NSLog(@"指纹认证失败!");
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                // do something on the UI thread
            });
        }];
    } else {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert" message:@"设备没有指纹认证功能" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        }];
        [alertController addAction:action];
        [self presentViewController:alertController animated:YES completion:nil];
    }
}


值得注意的是当用户按下指纹取得到指纹认证结果时,需要在主线程更新UI。

分享本文至:

WRITTEN BY

avatar
本文标签:iOSTouchID
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

27 条评论

  1. <a href="http://www.mondirco.com/air-max-90-hyperfuse-price-skor">air max 90 hyperfuse price</a> <a href="http://www.soknorealtor.com/joey-bosa-black-jersey-nflr">joey bosa black jersey</a> <a href="http://www.erneyapi.com/oakland-raiders-15-michael-crabtree-olive-2017-salute-to-service-limited-jersey-nflv">oakland raiders 15 michael crabtree olive 2017 salute to service limited jersey</a> <a href="http://www.tlclease.com/ralph-lauren-sky-blue-t-shirt-polor">ralph lauren sky blue t shirt</a> <a href="http://www.ziabio.com/asics-gel-noosa-tri-9-dam%C3%A4nner-trainersce">asics gel noosa tri 9 dam盲nner</a> <a href="http://www.charlomagno.com/ray-ban-aviator-blue-mirror-black-frame-sunglassesr">ray ban aviator blue mirror black frame</a>
    charlomagno http://www.charlomagno.com/

  2. <a href="http://www.chocopictures.com/nike-lunarglide-8-himmelblau-lila-schuhej">nike lunarglide 8 himmelblau lila</a> <a href="http://www.baluntan.com/vibram-five-fingers-m%C3%A4nner-grau-schwarz-gelb-schuhei">vibram five fingers m盲nner grau schwarz gelb</a> <a href="http://www.anderonedream.com/adidas-ace-16.1-svart-and-oransje-obuvj">adidas ace 16.1 svart and oransje</a> <a href="http://www.variaponsel.com/nike-huarache-dark-blu-scarpel">nike huarache dark blu</a> <a href="http://www.allmydibs.com/hommes-nike-air-max-2014-vert-noir-chaussuresh">hommes nike air max 2014 vert noir</a> <a href="http://www.macusaa.com/maschio-nike-kobe-10-nero-verde-scarpeh">maschio nike kobe 10 nero verde</a>
    moreheaddotts http://www.moreheaddotts.com/

  3. <a href="http://www.ptsbarwinslow.com/nike-air-force-1-low-gr%C3%A5-kvinners-obuvi">nike air force 1 low gr氓 kvinners</a> <a href="http://www.sarhallafk.com/nike-dunk-sky-high-wedge-zapatilla-de-deporte-negro-zapatosl">nike dunk sky high wedge zapatilla de deporte negro</a> <a href="http://www.philippikus.com/nike-free-tr-blu-scarpeh">nike free tr blu</a> <a href="http://www.pngoilgas.com/nike-free-trainer-5.0-light-blue-shoesk">nike free trainer 5.0 light blue</a> <a href="http://www.goficarwash.com/oakley-oil-rig-with-cherry-red-frame-fire-iridium-lens-sunglassesh">oakley oil rig with cherry red frame fire iridium lens</a> <a href="http://www.getairtijuana.com/femmes-nike-air-max-tailwind-5-noir-rouge-chaussuresl">femmes nike air max tailwind 5 noir rouge</a>
    bacaiptek http://www.bacaiptek.com/

  4. <a href="http://www.cherylblogs.com/marinen-bl%C3%A5-converse-kvinners-obuvi">marinen bl氓 converse kvinners</a> <a href="http://www.livefreshpbc.com/nike-sb-dunk-high-pro-rojo-zapatosl">nike sb dunk high pro rojo</a> <a href="http://www.bacaiptek.com/buty-nike-air-max-motion-lw-gym-rosso-scarpeh">buty nike air max motion lw gym rosso</a> <a href="http://www.socabets.com/nike-flyknit-air-max-purple-blue-shoesk">nike flyknit air max purple blue</a> <a href="http://www.sgeventportal.com/ray-ban-polarized-aviator-shades-sunglassesh">ray ban polarized aviator shades</a> <a href="http://www.isimsizsevda.com/adidas-stan-smith-cf-bleu-chaussuresl">adidas stan smith cf bleu</a>
    zeraxia http://www.zeraxia.com/

  5. <a href="http://www.cremontana.com/womens-nike-huarache-utility-black-denmark-shoeso">womens nike huarache utility black denmark</a> <a href="http://www.holeninegolf.com/billig-nike-shox-rivalry-kurpesb">billig nike shox rivalry</a> <a href="http://www.boobseze.com/adidas-climacool-shoes-green-zapatost">adidas climacool shoes green</a> <a href="http://www.divyangshop.com/girls-high-converse-shoesz">girls high converse</a> <a href="http://www.caveduperreux.com/nike-free-run-5.0-svart-bl%C3%A5-gr%C3%B8nn-schuhec">nike free run 5.0 svart bl氓 gr酶nn</a> <a href="http://www.fabloomsilk.com/nike-mens-tim-brown-limited-white-road-jersey-oakland-raiders-nfl-81-vapor-untouchable-nflu">nike mens tim brown limited white road jersey oakland raiders nfl 81 vapor untouchable</a>
    ezzolawaz http://www.ezzolawaz.com/

  6. <a href="http://www.georgesherry.com/ray-ban-polarized-foldable-round-sunglasses-nz-sunglassese">ray ban polarized foldable round sunglasses nz</a> <a href="http://www.jenalgroup.com/nike-carolina-panthers-authentic-font-long-sleeve-nfl-t-shirt-dark-grey-nflr">nike carolina panthers authentic font long sleeve nfl t shirt dark grey</a> <a href="http://www.badacamshotel.com/bon-march%C3%A9-under-armour-curry-4-femmes-jaune-skoa">bon march茅 under armour curry 4 femmes jaune</a> <a href="http://www.compressmyjs.com/nike-free-flyknit-4.0-junior-nationals-sneakere">nike free flyknit 4.0 junior nationals</a> <a href="http://www.fetison.com/nike-zoom-clear-out-2-rosso-argento-kurpesa">nike zoom clear out 2 rosso argento</a> <a href="http://www.neffloot.com/nike-free-flyknit-3.0-sports-direct-kick-sneakerb">nike free flyknit 3.0 sports direct kick</a>
    acforlessllc http://www.acforlessllc.com/

  7. <a href="http://www.blackopsequip.com/nike-air-max-97-s%C3%B8lv-bullet-sold-out-kurpesg">nike air max 97 s酶lv bullet sold out</a> <a href="http://www.chescombank.com/adidas-pr%C3%B8dator-soccer-orange-lyser%C3%B8d-schuhea">adidas pr酶dator soccer orange lyser酶d</a> <a href="http://www.dantint.com/adidas-springblade-naranja-negro-kds-butyf">adidas springblade naranja negro kds</a> <a href="http://www.digitisrael.com/mujeres-nike-cortez-amarillo-verde-kurpesd">mujeres nike cortez amarillo verde</a> <a href="http://www.evakloset.com/nike-free-run-5.0-v4-sail-rosa-discharge-butya">nike free run 5.0 v4 sail rosa discharge</a> <a href="http://www.freakumfest.com/vibram-fivefingers-komodo-hvit-rosa-schuheg">vibram fivefingers komodo hvit rosa</a>
    heimatd http://www.heimatd.com/

  8. <a href="http://www.starizle.com/jordan-4-gr%C3%BCn-and-schwarz-obuve">jordan 4 gr眉n and schwarz</a> <a href="http://www.notpotatoes.com/femmes-nike-zoom-pegasus-33-rouge-bleu-kurpesd">femmes nike zoom pegasus 33 rouge bleu</a> <a href="http://www.tedxuon.com/nike-free-run-3-5.0-orange-braun-schuhed">nike free run 3 5.0 orange braun</a> <a href="http://www.thejuicylucy.com/air-max-2017-femminile-nero-knight-kurpesf">air max 2017 femminile nero knight</a> <a href="http://www.almanyaonline.com/nike-air-max-zero-blau-wei%C3%9F-illustrated-obuva">nike air max zero blau wei脽 illustrated</a> <a href="http://www.trademelikes.com/nike-free-run-5.0-gr%C3%A5-korall-obuvf">nike free run 5.0 gr氓 korall</a>
    iflextoday http://www.iflextoday.com/

  9. <a href="http://www.mikespothole.com/puma-shophand-snapback-hats">puma shophand snapback</a> <a href="http://www.theclaydoctor.com/air-jordan-4-retro-gold-ugly-sneakere">air jordan 4 retro gold ugly</a> <a href="http://www.allthatspool.com/air-jordan-12-vivid-lyser%C3%B8d-wolf-gr%C3%A5-dam%C3%A6nd-obuvc">air jordan 12 vivid lyser酶d wolf gr氓 dam忙nd</a> <a href="http://www.ihavewed.com/womens-nike-buffalo-bills-22-vontae-davis-limited-whitepink-rush-fashion-nfl-jersey-nflw">womens nike buffalo bills 22 vontae davis limited whitepink rush fashion nfl jersey</a> <a href="http://www.cloudsmartin.com/2014-15-chelsea-fc-26-terry-home-soccer-shirt-kit-nflv">2014 15 chelsea fc 26 terry home soccer shirt kit</a> <a href="http://www.myachingoa.com/nike-free-3.0-v4-damen-lila-pink-skog">nike free 3.0 v4 damen lila pink</a>
    mikespothole http://www.mikespothole.com/

  10. <a href="http://www.iremaxvn.com/billig-nike-vapormax-dam%C3%A4nner-rosa-skod">billig nike vapormax dam盲nner rosa</a> <a href="http://www.multinutwraps.com/philadelphia-flyers-jersey-nflc">philadelphia flyers jersey</a> <a href="http://www.vipartonline.com/buy-burberry-belt-online-india-beltr">buy burberry belt online india</a> <a href="http://www.wantaoren.com/ray-ban-rb4098-jackie-ohh-ii-sunglasses-shiny-black-egg-sunglassesc">ray ban rb4098 jackie ohh ii sunglasses shiny black egg</a> <a href="http://www.tokodanaya.com/orlando-magic-white-blue-tisa-snapback-cap-style-2-handsome-style-hatg">orlando magic white blue tisa snapback cap style 2 handsome style</a> <a href="http://www.dinerwareoc.com/ray-ban-rb2140-wayfarer-sunglasses-tortoise-frame-brown-polarized-sunglassesd">ray ban rb2140 wayfarer sunglasses tortoise frame brown polarized</a>
    nanainchief http://www.nanainchief.com/

  11. <a href="http://www.freizeittrend.com/nike-zoom-winflo-3-dam%C3%A4nner-grau-rot-schuhea">nike zoom winflo 3 dam盲nner grau rot</a> <a href="http://www.instanalo.com/nike-solarsoft-mule-blanco-azul-scarpeb">nike solarsoft mule blanco azul</a> <a href="http://www.olafhuth.com/womens-nike-huarache-utility-black-denmark-shoeso">womens nike huarache utility black denmark</a> <a href="http://www.pecanfirewood.com/nike-air-force-1-mid-wheat-kvinners-kurpesb">nike air force 1 mid wheat kvinners</a> <a href="http://www.ezzolawaz.com/nike-free-run-2-all-black-for-sale-zapatost">nike free run 2 all black for sale</a> <a href="http://www.suchmeldungen.com/girls-high-converse-shoesz">girls high converse</a>
    bootsoffprice http://www.bootsoffprice.com/

  12. <a href="http://www.swnblog.com/chicago-bulls-michael-jordan-hoodie-new-adult-size-medium-other-nflv">chicago bulls michael jordan hoodie new adult size medium other</a> <a href="http://www.weimpactmds.com/nike-zoom-clear-out-1-red-gold-skof">nike zoom clear out 1 red gold</a> <a href="http://www.relsflorida.com/nike-free-run-3-5.0-white-skob">nike free run 3 5.0 white</a> <a href="http://www.votuongluan.com/cincinnati-reds-hats-for-sale-wholesalers-hata">cincinnati reds hats for sale wholesalers</a> <a href="http://www.hanayaflowers.com/green-womens-nike-cortez-shoes-runningf">green womens nike cortez shoes</a> <a href="http://www.jlchatlaw.com/jordan-11-hvid-light-bl%C3%A5-schuhea">jordan 11 hvid light bl氓</a>
    theclaydoctor http://www.theclaydoctor.com/

  13. <a href="http://www.kainjipark.com/youth-jason-kelce-limited-camo-nike-jersey-nfl-philadelphia-eagles-62-rush-realtree-nflr">youth jason kelce limited camo nike jersey nfl philadelphia eagles 62 rush realtree</a> <a href="http://www.lapthelakes.com/zalando-zapatillas-adidas-zx-flux-skoa">zalando zapatillas adidas zx flux</a> <a href="http://www.delmaroffice.com/jordan-future-sport-blue-reflective-sneakere">jordan future sport blue reflective</a> <a href="http://www.medieneinsatz.com/adidas-pr%C3%B8dator-instinct-ag-svart-kurpesa">adidas pr酶dator instinct ag svart</a> <a href="http://www.linexcanton.com/air-jordan-6-varsity-red-2017-events-sneakerb">air jordan 6 varsity red 2017 events</a> <a href="http://www.saskostomy.com/nike-air-max-tailwind-6-green-purple-shoesg">nike air max tailwind 6 green purple</a>
    cloudsmartin http://www.cloudsmartin.com/

  14. <a href="http://www.agichipay.com/florida-panthers-snapback-black-hatb">florida panthers snapback black</a> <a href="http://www.millsbulb.com/adidas-porsche-design-iii-coral-runninge">adidas porsche design iii coral</a> <a href="http://www.hamshrd.com/maschio-air-yeezy-ii-2-sp-max-90-verde-rosso-schuhea">maschio air yeezy ii 2 sp max 90 verde rosso</a> <a href="http://www.lroyroofing.com/hommes-nike-flynit-air-max-vert-bleu-scarpeb">hommes nike flynit air max vert bleu</a> <a href="http://www.golfbodyshop.com/nike-air-max-2019-green-uk-shoeso">nike air max 2019 green uk</a> <a href="http://www.yufnsyb.com/nike-air-max-tailwind-8-bl%C3%A5-tooth-kurpesc">nike air max tailwind 8 bl氓 tooth</a>
    georginabauer http://www.georginabauer.com/

  15. avatar moveinplace

    <a href="http://www.cmetechnology.com/air-jordan-vii-7-retro-b%C3%B8rn-scarpea">air jordan vii 7 retro b酶rn</a> <a href="http://www.hepseninle.com/nike-free-flyknit-5.0-blu-ink-kurpesf">nike free flyknit 5.0 blu ink</a> <a href="http://www.mecazadam.com/nike-mens-kyle-emanuel-limited-black-jersey-los-angeles-chargers-nfl-51-2016-salute-to-service-nflr">nike mens kyle emanuel limited black jersey los angeles chargers nfl 51 2016 salute to service</a> <a href="http://www.medfarmailac.com/nike-kobe-9-gold-crimson-schwarz-kurpesf">nike kobe 9 gold crimson schwarz</a> <a href="http://www.mileikanea.com/femminile-nike-air-force-1-gituttio-rosso-schuhef">femminile nike air force 1 gituttio rosso</a> <a href="http://www.paolamoney.com/adidas-ultra-boost-core-noir-jack-obuvg">adidas ultra boost core noir jack</a>
    moveinplace http://www.moveinplace.com/

  16. avatar suchmeldungen

    <a href="http://www.swnblog.com/nike-free-rn-red-up-sneakere">nike free rn red up</a> <a href="http://www.weimpactmds.com/nike-flyknit-racer-lagoon-blau-xm%C3%A4nner-kurpesa">nike flyknit racer lagoon blau xm盲nner</a> <a href="http://www.relsflorida.com/kd-8-green-new-sneakerb">kd 8 green new</a> <a href="http://www.votuongluan.com/nike-lebron-13-low-team-red-line-shoesg">nike lebron 13 low team red line</a> <a href="http://www.hanayaflowers.com/chicago-blackhawks-bucket-hat-hats">chicago blackhawks bucket hat</a> <a href="http://www.jlchatlaw.com/nike-air-max-90-vt-pink-blue-sneakerf">nike air max 90 vt pink blue</a>
    suchmeldungen http://www.suchmeldungen.com/

  17. avatar boobseze

    <a href="http://www.acforlessllc.com/red-yellow-womens-nike-air-max-1-essential-shoes-runninge">red yellow womens nike air max 1 essential shoes</a> <a href="http://www.thehodostore.com/converse-chuck-taylor-gore-tex-hi-duck-camo-zapatosu">converse chuck taylor gore tex hi duck camo</a> <a href="http://www.gandoff.com/nike-flyknit-racer-legion-bl%C3%A5-springs-chaussuresa">nike flyknit racer legion bl氓 springs</a> <a href="http://www.langbenlang.com/limited-robbie-gould-jersey-chicago-bears-9-camo-fashion-black-nfle">limited robbie gould jersey chicago bears 9 camo fashion black</a> <a href="http://www.glennloovens.com/air-max-plus-white-tiger-runningg">air max plus white tiger</a> <a href="http://www.kamilotomotiv.com/zdeno-chara-33-boston-bruins-reebok-premier-alternate-jersey-small-nflv">zdeno chara 33 boston bruins reebok premier alternate jersey small</a>
    boobseze http://www.boobseze.com/

  18. avatar ycbrowsbeauty

    <a href="http://www.cakeeaterspgh.com/nike-roshe-run-speckle-orange-grey-shoesc">nike roshe run speckle orange grey</a> <a href="http://www.leesgoedplus.com/billig-nike-zoom-pegasus-32-kvinders-bl%C3%A5-skog">billig nike zoom pegasus 32 kvinders bl氓</a> <a href="http://www.lieupekings.com/yellow-purple-womens-nike-air-force-1-high-shoes-sportsf">yellow purple womens nike air force 1 high shoes</a> <a href="http://www.marieebeaute.com/nike-air-max-tailwind-5-orange-dream-runningd">nike air max tailwind 5 orange dream</a> <a href="http://www.dentaleden.com/limited-jason-hanson-jersey-detroit-lions-4-camo-fashion-black-nflg">limited jason hanson jersey detroit lions 4 camo fashion black</a> <a href="http://www.jellyville.com/nike-flyknit-lunar-3-silver-black-skoa">nike flyknit lunar 3 silver black</a>
    [url=http://www.ycbrowsbeauty.com/]ycbrowsbeauty[/url]

  19. avatar allenchute

    <a href="http://www.momandpopop.com/hermes-alligator-bracelet-hermesr">hermes alligator bracelet</a> <a href="http://www.artlaurey.com/adidas-nmd-runner-vapour-pink-light-onix-exclusive-zero-shoesv">adidas nmd runner vapour pink light onix exclusive zero</a> <a href="http://www.ochapan.com/coach-tote-crossgrain-leather-coacha">coach tote crossgrain leather</a> <a href="http://www.brooklyngay.com/asics-gel-kinsei-2-dam%C3%A4nner-schwarz-shoesa">asics gel kinsei 2 dam盲nner schwarz</a> <a href="http://www.royphelps.com/nike-kyrie-2-purple-skos">nike kyrie 2 purple</a> <a href="http://www.agneaublanc.com/burberry-belt-price-singapore-beltr">burberry belt price singapore</a>
    allenchute http://www.allenchute.com/

  20. avatar PDM系统

    IOS开发比安卓的还是有不少技术含量的

  21. avatar 宁波PLM

    这文章值得学习一下

  22. avatar PDM系统

    这么好的文章值得学习

  23. avatar 盘古科技

    这真是好东西  认真学习一下

  24. avatar 老董优惠码

    不错 感谢分享

  25. avatar 轿车托运公司

    好东西 点个赞

欢迎留言




用户登录

sitemap