Last active
August 14, 2020 14:32
-
-
Save jazzycamel/ddfa2252fdeb9f4ee4e1f1ba3c1a9a4a to your computer and use it in GitHub Desktop.
Using iOS Face ID (and Touch ID) with Qt5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "biometrics.h" | |
#ifdef Q_OS_IOS | |
#include "localAuth-c-interface.h" | |
#endif | |
#include <QDebug> | |
Biometrics::Biometrics(QObject *parent) : QObject(parent) | |
{ | |
} | |
void Biometrics::invokeBiometrics(){ | |
#ifdef Q_OS_IOS | |
qDebug() << "Local Auth:" << localAuth(); | |
#endif | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef BIOMETRICS_H | |
#define BIOMETRICS_H | |
#include <QObject> | |
class Biometrics : public QObject | |
{ | |
Q_OBJECT | |
public: | |
explicit Biometrics(QObject *parent = nullptr); | |
public slots: | |
void invokeBiometrics(); | |
signals: | |
}; | |
#endif // BIOMETRICS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef LOCALAUTHCINTERFACE_H | |
#define LOCALAUTHCINTERFACE_H | |
bool localAuth(); | |
#endif // LOCALAUTHCINTERFACE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOOL localAuth(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <LocalAuthentication/LocalAuthentication.h> | |
BOOL localAuth() { | |
LAContext *laContext=[[LAContext alloc] init]; | |
NSError *authError=nil; | |
NSString *localisedReasonString=@"App would like to make logging in easier."; | |
__block BOOL result=false; | |
dispatch_semaphore_t sema=dispatch_semaphore_create(0); | |
if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]){ | |
[laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:localisedReasonString reply:^(BOOL success, NSError *error){ | |
result=success; | |
dispatch_semaphore_signal(sema); | |
}]; | |
} else return false; | |
if(![NSThread isMainThread]){ | |
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); | |
} else { | |
while(dispatch_semaphore_wait(sema, DISPATCH_TIME_NOW)){ | |
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0]]; | |
} | |
} | |
return result; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
ios { | |
OBJECTIVE_HEADERS += localAuth.h | |
OBJECTIVE_SOURCES += localAuth.mm | |
HEADERS += localAuth-c-interface.h | |
LIBS += -framework LocalAuthentication | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment