fbpx

Refactoring: Face ID/Touch ID for iOS 13

Back in February 2015, my article on Touch ID was published on raywenderlich.com. It was written in Swift for Xcode 8. Every year or so, I would update the article while I was an author on the iOS Team. Here’s a link to the latest version — How To Secure iOS User Data: The Keychain and Biometrics – Face ID or Touch ID. A few months ago, I had to update one of my own apps for iOS 13 with Apple’s biometric identification framework, Local Authentication. Incidentally, my app was also still supporting Objective-C. Here’s follow up on what I had to change. As a bonus you can also take your user to Settings in case they have disabled

First thing is to add Local Authentication at the top of the Login view controller.


#import <LocalAuthentication/LocalAuthentication.h>

Next create an action for the Touch ID method:

– (IBAction)touchIDAction:(id)sender {
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @”Used for quick and secure access to the test app”;
//…
}

After that we need to check if the device can support biometrics with canEvaluatePolicy and have an error ready.

Inside the touchIDAction add:

if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
error:&authError]) {
// 1. successful steps
} else {
// 2. Oops. There's a error!
}

Inside the canEvaluatePolicy, we’ll use evaluatePolicy:localizedReason:reply. The reply will have a block that either succeeds or fails with our error.

// 1. successful steps.
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates

// using a Keychain utility method to get the email and password
NSString *passwordFound = [KeychainUtils getPasswordForUsername:self->emailTextField.text andServiceName:@"My_app" error:nil];
self->passwordTextField.text = passwordFound;
self->usingSecureID = true; // a Bool I added to keep track
[self loginAction:nil];
[NSLog showWithStatus:@"Logging_In"];
});
});
} else {
// User did not authenticate successfully, look at error and take appropriate action

//I'm using a showAlert method to bring up a UIAlertViewController
[self showAlert: @"There was a problem verifying your identity." withTitle:@"Error!"];
return;
}
}];

What do we do if there is an error enabling Face ID/Touch ID? It could be because the user has disabled the feature. What’s new is that we can now take the user to your application settings — without a hack.

Initially you can pop up an alert to inform the user. Added to UIKit in iOS 8, UIApplicationOpenSettingsURLString lets you add a button to the alert that will take the user to your app in Settings, where they can enable Face ID/Touch ID.

// Could not evaluate policy; look at authError and present an appropriate message to user
NSString *title = @"Error!";
  NSString *message = @"Your device cannot authenticate using TouchID.";
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
// do we need to return animation?
                                                          }];
    // open your app in Settings
    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    UIApplication *application = [UIApplication sharedApplication];
    NSString *settingTitle = @"Settings";
    UIAlertAction* settingsAction = [UIAlertAction actionWithTitle:settingTitle style:UIAlertActionStyleDefault
                                                           handler:^(UIAlertAction * action) {
                                                             [application openURL:url  options:@{}
completionHandler:nil];
                                                           }];
    [alert addAction:settingsAction];
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
    return;
}

The whole method would look like this:

- (IBAction)touchIDAction:(id)sender {
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;

NSString *myLocalizedReasonString = @"Used for quick and secure access to the test app";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
// 1. successful steps

[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates

// using a Keychain utility method to get the email and password
NSString *passwordFound = [KeychainUtils getPasswordForUsername:self->emailTextField.text andServiceName:@"My_app" error:nil];
self->passwordTextField.text = passwordFound;
self->usingSecureID = true; // a Bool I added to keep track
[self loginAction:nil];
[NSLog showWithStatus:@"Logging_In"];
});
});
} else {
// User did not authenticate successfully, look at error and take appropriate action

//I'm using a showAlert method to bring up a UIAlertViewController
[self showAlert: @"There was a problem verifying your identity." withTitle:@"Error!"];
return;
}
}];
} else {
// 2. Oops. There's a error!

// Could not evaluate policy; look at authError and present an appropriate message to user
NSString *title = @"Error!";
  NSString *message = @"Your device cannot authenticate using TouchID.";
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
// do we need to return animation?
                                                          }];
    // open your app in Settings
    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    UIApplication *application = [UIApplication sharedApplication];
    NSString *settingTitle = @"Settings";
    UIAlertAction* settingsAction = [UIAlertAction actionWithTitle:settingTitle style:UIAlertActionStyleDefault
                                                           handler:^(UIAlertAction * action) {
                                                             [application openURL:url  options:@{}
completionHandler:nil];
                                                           }];
    [alert addAction:settingsAction];
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
    return;
}
}
}

Talk: 5 Ways to Level Up Your Mobile Development

Talk Abstract

Making successful apps is daunting. New skills must be attained. Choosing frameworks, and building safe code requires knowledge. This talk covers ways to acquire new knowledge, safe practices, and how to get the various parts of a project done. The work, as it turns out, is more than just code.

Talk Description

Being a successful developer can mean many things. You may want your apps to be used by many people—often, and with pleasure, surprise, and delight. You may also be looking to level-up your career or to teach others. Heck, you might even want to podcast about development. So, how do you get into the position to be successful?

This talk takes a look at techniques to level-up your mobile toolchain. I like to say it takes more than just code to make an app. In some ways, you need to be a multipotentialite. We’ll look at how you can use aspects of several sciences and best practices to tool-up for success. We’ll cover the reasons that make products successful, how to create a community, why it’s important to give back, and how to decide what to include (and what to cut). On the coding side, we’ll look at strategies for good code, technical debt, and project management. We’ll even look at brain science to find out how to retain all of this info and the skills you’ll need to be a success.

Notes

I am a mobile app developer, podcaster and artist. I have taught iOS dev, Swift and Objective-C. I’m currently a Development Manager – iOS at TD Bank. I also run iT Guy Technologies, a software development company in Toronto, Canada. I studied Fine Arts before there were Macs and I’ve worked for many years in software development, IT, graphic design, publishing and printing. I’m the founder, producer and host of the More Than Just Code Podcast — a podcast covering mobile app development & business and SpockCast a sci-fi pop culture podcast. Tim is also co-host of Roundabout Creative Chaos podcast.

I have given several talks over the years. I’ve spoken at 360iDev, Indie Devstock and Expo Canada. I spoken on iOS app development, developer skills as well as macOS and Unix basics.

Points:

  • a short discussion of the More Than Just Code podcast. To give guidance to fellow developers on iOS dev and App business
  • Start with “Why”. Intention is important in what we do and deliver to others.
  • How am I making a difference in other’s lives?
  • How to make a dent in the universe, through your work. Why do we do the things we do and will we be remembered for it.
  • I wrote an article about “Learning After 50”, which lead to brain science and neuroplasticty
  • “Hacking your brain”. How the brain works – a discussion on forming memories and behaviours from brain research and how you can use practice to enhance your studies
  • examples of how I use this new knowledge to learn new songs and instruments. I also use this to learn new skills related to mobile development such as SwiftUI and Combine.
  • Community
  • giving constructive and helpful code reviews and peer reviews.
  • giving back to others in our iOS and mobile dev community.
  • becoming a mentor to others.
  • We are taught how to drive but there is no similar course on how to communicate.
  • looking at the amygdala and neocortex and how they influence our reactions and communication.
  • we all have a negativity bias that leads to self doubt and imposter syndrome
  • the role of Craftsmanship in our work.
  • adopting SwiftUI and Combine and techniques to get involved based on what we learned.
  • where we are in the universe as an object lesson about self importance.
  • concludes with an example of iPad empowering communication.

Command CompileAssetCatalog failed with a nonzero exit code

pulling out hair

Oh my good gravy!

Here’s the back story. I was working on a cleanly installed Mac after migrating user accounts onto it. My account is not the primary admin account (eg. UID 501). Xcode was installed with all the permissions set to that primary user, an account that never logs onto this Mac!

I have been having multiple issues trying to get Xcode to build on this Mac — my traveling Mac. I like to leave my bread and butter Mac at home and travel with an 11 inch MacBook Air. Most Mac’s are too big to be easily opened on an airplane, in Economy. I cannot afford to fly business class since the Indie-Apocalypse hit in 2014.

The owner permissions were all f’ed up, where Xcode does it’s build business. The last straw was the “Command CompileAssetCatalog” failure.

To fix this, change the permissions on the Xcode folder in your home Library (which all files should be all owed my login username.) Pro Tip: replace your username where you see mine — tmitra

cd ~/Library/Developer/Xcode/UserData
ls -la

Checking the ownership of this folder showed I was not the owner. I fixed the permissions on the Xcode directory here:

sudo chown -R tmitra ~/Library/Developer/Xcode

Build and Run.

FWIW I also had to fix permissions elsewhere:

Error: Failed to create temporary directory: /Library/Developer/Xcode/UserData/IB Support/Simulator Devices/

sudo chown -R tmitra ~/Library/Developer/CoreSimulator/Devices

“tmp” couldn’t be removed because you don’t have permission to access it

sudo chown tmitra /Users/tmitra/Library/Developer/Xcode/DerivedData

Pro Tip: Also check that you are building with the correct Xcode on your Mac. To check which is building:

xcode-select -p
/Applications/Xcode.app/Contents/Developer

To change the path:

xcode-select -s /Applications/[put your Xcode.app here]/Contents/Developer

Your mileage may vary.

Beavers & Bellwethers

This week we follow up on the case of an Oregon man who uses the title “engineer”. Apple lowered its Q1 guidance based on lower expectations. Apple also starts assembling premium iPhones in India. Apple’s new plans may reveal what projects will be worked on around the United States. Netflix has pulled iTunes billing for users. Picks: Gesture based app selection and organization, Learn Talks. 

EPISODE LINKS

Episode 227 – They’re Everywhere! They’re Everywhere!

We fact check on CSIS, overtime hockey, defeating Face ID, and git commit –amend. #askMTJC brings up promo codes for IAP and the bands on the Stanley Cup. Apple stock sees its best performance in five years. The main topic is top paying tech companies in 2018 and comparative compensation vs cost of living. We review the highlights of the More Than Just Code podcast in 2018. We also choose our top picks for 2018. Picks: Google Home Alone. After Show: The physics MP3 compression and Boxing Day.

Episode 227 Show Links:

Episode 227 Picks:

Keep in touch

Episode 226 – Bendgate Pro

This week Greg Heo leads the crew as they discuss the Windows 95 ugly holiday sweater, NHL hockey overtime 3 on 3, and protocol conformance. We follow up on Apple shutting down Music’s Connect feature, Sega Genesis Classics are playable on Amazon Fire, the C64 Mini, Windows Sandbox, Apple is producing new Peanuts content, breaking into Amazon face recognition with 3D printed heads, T-Mobile eSIM support, Apple will allow IAP gifted to Friends & Family. Apple will build new campus in Austin and add jobs across the US. Cydia Store shuts down. Apple confirms some iPad Pros ship slightly bent, but says it’s normal. Picks: Xcode Comment-Spell-Checker, 6 Audio books on Apple Books, The 8-Bit Guy, Functional Swift 2018 videos, MagazineLayout

Episode 226 Show Links:

Episode 226 Picks:

Episode 225 – A BIt Of A Fumble

We get an iOS shortcut for bypassing paywalls in #askMTJC. We follow up with a deep dive into poor iPhone XR adoption figures, Google+ has potentially exposed data from 52M users, Infinity Blade games removed from the App Store, Apple appeals to China’s iPhone ban, and Samsung removes the headphone jack. We take a look at some Swift tricks that you may not know about. Swift 5.0 wants us to try some nice breaking changes. You can record ARKit sessions in order to debug. It’s apparently really easy to add a second display to an iOS app. Picks: A look at the Original 1984 Macintosh User Manual, Swift Docker image hosted by Apple.

Episode 225 Show Links:

Episode 225 Picks:

Episode 224 – Siri, Open The Pod Bay Doors

We discuss using Siri to access application settings in our #askMTJC. We fact check on Indian Partitioning dates. We follow up on Apple Music arriving on Amazon’s Echo, Apple vs Qualcomm trial date set, 5G iPhone maybe as late as 2020, wireless charging for AirPods and AT&T first to support eSim. We discuss changing laws with GitHub pull requests. Apple’s program for women entrepreneur developers. Siri Shortcuts Not Working for many people. Real-time text support for Wi-Fi calling. Touch ID used in app scams to bilk users. Picks: Xcode Short Cuts, Run macOS on iPad, Play Retro Dark Castle on iPad with System 6.0.8, Optimizing Siri on HomePod in Far‑Field Settings

Episode 224 – Show Links:

Episode 224 Picks

Episode 223 – With Scary Air Quotes

We follow up on #askMTJC about NFL blackouts, Canadian sports channel, and Canada’s Bill 101. We follow up on Jony Ive designed diamond ring, App Store Connect holiday closure, iPhone XR price drop in Japan, and surprisingly the iPhone XR is Apple’s best seller. We also follow up on Black Friday 2018 deals. Amazon introduces it’s own Arm processor, and Amazon Pay will take on Apple Pay. The US Supreme Court is to decide if Apple can be sued for high prices and its monopoly. Picks: Amazon’s own ‘Machine Learning University’ now available to all developers, simctl – NSHipster, Linking to Subscription Management Settings, SubEthaEdit open source, Creative Selection: Inside Apple’s Design Process During the Golden Age of Steve Jobs.

Episode 223 Show Links:

Episode 223 Picks:

Episode 222 – Everyone’s A Publisher

We follow up on folding phones as Google adds support to Android. Apple cuts production on all new iPhone X series phones. Verizon will bring eSIM support for iPhones. Amazon US will now sell Macs for Apple. Prince William weighs in on social network giants lack of discretion. Tim Cook says regulations as inevitable. Apple has bought a privacy-conscious AI start up. Picks: Swift Heroes 2018 conference videos, Mini vMac for iOS, Deep Learning Specialization

Episode 222 Show Links:

Episode 222 Picks:

Copyright © 2000-2022 iT Guy Technologies, a division of 1654328 Ontario Ltd Proudly powered by WordPress

This site has been visited at least times since March 2, 2000.