software-mariodiana
3/27/2019 - 6:03 PM

Objective-C method to detect whether the iOS device has a "notch," à la iPhone X.

Objective-C method to detect whether the iOS device has a "notch," à la iPhone X.

#import <LocalAuthentication/LocalAuthentication.h>

/**
 * Return YES if iOS device has a notch; NO, otherwise.
 */
- (BOOL)hasDeviceNotch
{
    if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)) {
        return NO;
    }
    else {
        LAContext* context = [[LAContext alloc] init];
        [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
                             error:nil];
                             
        return [context biometryType] == LABiometryTypeFaceID;
    }
}