I am using this below code for detecting the Touch ID availability in device it works fine
- (BOOL)canAuthenticateByTouchId
{
if ([LAContext class])
{
return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
}
return NO;
}
- (IBAction)touchIDAvailability
{
if([self canAuthenticateByTouchId])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Congrats"
message:#"Your device have TouchID"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
else
{
str = #"TouchID is not available in your device";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops"
message:str
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}
After detecting the Touch ID availability i want to find the Touch Id is configured or not
NSString *str;
if (LAErrorTouchIDNotEnrolled)
{
str = #"Please configure your TouchID in Settings > Touch ID & Passcode";
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops"
message:str
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
i configured Touch ID but it still Entered into LAErrorTouchIDNotEnrolled this loop. Can any one knows tell me.
You can check whether user is configured or not using below
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL succes, NSError *error) {
}
Here is the complete code for Touch ID
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
myContext.localizedFallbackTitle=#"Login with Password";//optional for hiding enter password button
NSString *myLocalizedReasonString = #"For touch ID Users Ignore this pop-up and proceed to login with you finger now";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL succes, NSError *error) {
if (succes) {
[self showMessage:#"Authentication is successful" withTitle:#"Success"];
NSLog(#"User authenticated"); }
} else {
switch (error.code) {
case LAErrorAuthenticationFailed:
[self showMessage:#"Authentication is failed" withTitle:#"Error"];
NSLog(#"Authentication Failed");
break;
case LAErrorUserCancel:
[self showMessage:#"You clicked on Cancel" withTitle:#"Error"];
NSLog(#"User pressed Cancel button");
break;
case LAErrorUserFallback:
[self showMessage:#"You clicked on \"Enter Password\"" withTitle:#"Error"];
NSLog(#"User pressed \"Enter Password\"");
break;
default:
[self showMessage:#"Touch ID is not configured" withTitle:#"Error"];
NSLog(#"Touch ID is not configured");
break;
}
NSLog(#"Authentication Fails");
}
}];
} else {
NSLog(#"Can not evaluate Touch ID");
NSString *str = #"TouchID is not available in your device";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops"
message:str
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}
-(void) showMessage:(NSString*)message withTitle:(NSString *)title
{
[[[UIAlertView alloc] initWithTitle:#"AppName" message:message delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:nil, nil] show];
}
Hope it helps you..!
Related
My login and signup buttons WERE working but for some reason after I fill out the unsername and password field - and press the login button - the botton wont push to my inbox controller. But if i stop my project and then re run it, it will load as logged in. I don't know why! Any help would be appreciated--
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.hidesBackButton = YES;
}
- (IBAction)login:(id)sender {
NSString *username = [self.usernameField.text
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *password = [self.passwordField.text
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([username length] == 0 || [password length] == 0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Oops!"
message:#"Make sure you enter a username and password!"
delegate:Nil cancelButtonTitle:#"Okey"
otherButtonTitles:nil];
[alertView show];
} else {
[PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry!"
message:[error.userInfo objectForKey:#"error"]
delegate:Nil cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
} else {
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
}
}
#end
I want to implement touch id feature into an app, for that i have written code:
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:#"Are you the device owner?"
reply:^(BOOL success, NSError *error) {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"There was a problem verifying your identity."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
return;
}
if (success) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"You are the device owner!"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"You are not the device owner."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Your device cannot authenticate using TouchID."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
I don't have devices which support touch id feature, So where i can test it to see its functionality work fine or not.
Any help would be appreciated. Thanks.
You can only test TouchID on a real device. The simulator does not support this.
I have followed the guidelines and also the example for Touch ID API from Apple documentation. I have used the example in my applications. I could able to login using Touch ID. But the problem is its responsive is very very slow. After I put my finger on the Touch ID , at least 10 seconds I have to wait to get verify success/failure. I have used the code in app delegate file. I have also tested with different apps but the result is the same "delayed response". Guys please help me in this case.
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = <#String explaining why app needs authentication#>;
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
// User authenticated successfully, take appropriate action
dispatch_async(dispatch_get_main_queue(), ^{
// write all your code here
});
} else {
// User did not authenticate successfully, look at error and take appropriate action
switch (error.code) {
case LAErrorAuthenticationFailed:
NSLog(#"Authentication Failed");
break;
case LAErrorUserCancel:
NSLog(#"User pressed Cancel button");
break;
case LAErrorUserFallback:
NSLog(#"User pressed \"Enter Password\"");
break;
default:
NSLog(#"Touch ID is not configured");
break;
}
NSLog(#"Authentication Fails");
}
}];
} else {
// Could not evaluate policy; look at authError and present an appropriate message to user
}
You have to display the alertviews in the main thread with
dispatch_async(dispatch_get_main_queue(), ^{
//update ui
});
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
// Authenticate User
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:#"Please verify that you are the device owner in order to place the order"
reply:^(BOOL success, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"There was a problem verifying your identity."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
return;
}
if (success) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"You are the device owner!"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"You are not the device owner."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
});
}];
}
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Your device cannot authenticate using TouchID."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
As other said, you have to do UI thing on the main thread, for Swift 3.0 it's:
myContext.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { (success, evaluateError) in
DispatchQueue.main.async {
if (success) {
//success
} else {
//failure
}
}
}
It may be an easy question, but I am tired of it
Is there any setting for Facebook app (Which we set while creating an App in Facebook developer's site) for making "invite friend" functionality to be worked.
I am using WebDialog method as follows,
FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:FacebookInviteMessage
title:#"Invite Friends"
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
With the same method I am able to invite friend, when I am using the Facebook APP ID of another sample code in my project. But when I am using my own project's Facebook APP ID, invite is not working when I am getting Success in result url.
So I think there would be some setting in developer's site of Facebook.
Can anyone help for this
The complete code is
NSDictionary *parameters = self.fbidSelection ? #{#"to":self.fbidSelection} : nil;
MIDLog(#"self.fbidSelection %#",self.fbidSelection);
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:FacebookInviteMessage
title:#"Invite Friends"
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
NSString *strResultUrl = [resultURL absoluteString];
if (result == FBWebDialogResultDialogCompleted && ![strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Web dialog complete: %#", resultURL);
if (![resultURL query])
{
return;
}
NSDictionary *params = [self parseURLParams:[resultURL query]];
NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
for (NSString *paramKey in params)
{
if ([paramKey hasPrefix:#"to["])
{
[recipientIDs addObject:[params objectForKey:paramKey]];
}
}
if ([params objectForKey:#"request"])
{
NSLog(#"Request ID: %#", [params objectForKey:#"request"]);
}
if ([recipientIDs count] > 0)
{
//[self showMessage:#"Sent request successfully."];
//NSLog(#"Recipient ID(s): %#", recipientIDs);
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:#"Success!" message:#"Invitation(s) sent successfuly!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alrt show];
alrt = nil;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success" message:FacebookInviteSuccess delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
// [self navigateToSearch];
}
else if (result == FBWebDialogResultDialogCompleted && [strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Cancel Clicked");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Cancelled" message:nil delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
}
else {
MIDLog(#"Web dialog not complete, error: %#", error.description);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:InternetFailError delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
alert.tag = 15115;
[alert show];
alert = nil;
}
}
friendCache:self.friendCache];
}
Thank you
It may be an easy question but can anybody tell me.
Is there any setting we need to do in the app (in Facebook developer site) for invite friends?
I have done all in code to invite friends.
When I substitute the Facebook APP ID of a sample code in which invite friend is working, then my code is also working fine.
But when I substitute my APP ID then the process is going fine, showing me successfully invitation message, but invitation is not sent.
I am using the following code:
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:FacebookInviteMessage
title:#"Invite Friends"
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
NSString *strResultUrl = [resultURL absoluteString];
if (result == FBWebDialogResultDialogCompleted && ![strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Web dialog complete: %#", resultURL);
if (![resultURL query])
{
return;
}
NSDictionary *params = [self parseURLParams:[resultURL query]];
NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
for (NSString *paramKey in params)
{
if ([paramKey hasPrefix:#"to["])
{
[recipientIDs addObject:[params objectForKey:paramKey]];
}
}
if ([params objectForKey:#"request"])
{
NSLog(#"Request ID: %#", [params objectForKey:#"request"]);
}
if ([recipientIDs count] > 0)
{
//[self showMessage:#"Sent request successfully."];
//NSLog(#"Recipient ID(s): %#", recipientIDs);
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:#"Success!" message:#"Invitation(s) sent successfuly!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alrt show];
alrt = nil;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success" message:FacebookInviteSuccess delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
}
else if (result == FBWebDialogResultDialogCompleted && [strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Cancel Clicked");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Cancelled" message:nil delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
}
else {
MIDLog(#"Web dialog not complete, error: %#", error.description);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:InternetFailError delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
alert.tag = 15115;
[alert show];
alert = nil;
}
}
friendCache:self.friendCache]
I provided the canvas URL in the application settings under Facebook developer site and It works for me