Created
November 27, 2015 03:07
-
-
Save horike37/ff3a7d2a2f373020cc8e to your computer and use it in GitHub Desktop.
startInstanceのLambdaを起動させるobjective-cのコード
This file contains 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
- (IBAction)startInstance:(id)sender { | |
LAContext *myContext = [[LAContext alloc] init]; | |
NSError *error = nil; | |
// 端末が指紋認証を使えるかどうか判定 | |
if([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { | |
NSString *myLocalizedReasonString = @"指紋認証せんかい!"; | |
[self.activityIndicator startAnimating]; | |
// 指紋認証画面を表示 | |
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics | |
localizedReason:myLocalizedReasonString | |
reply:^(BOOL success, NSError *error) { | |
if(success) { | |
// 指紋認証成功 | |
NSString *functionName = @"start-instance"; | |
NSLog(@"Function Name: %@", functionName); | |
NSError *jsonError = nil; | |
NSString *jsonInput = [NSString stringWithFormat:@"{\"instance_id\":\"%@\"}", self.instanceId]; | |
NSData *jsonData = [jsonInput dataUsingEncoding:NSUTF8StringEncoding]; | |
NSDictionary *parameters = [NSJSONSerialization JSONObjectWithData:jsonData | |
options:NSJSONReadingAllowFragments | |
error:&jsonError]; | |
NSLog(@"Json Input: %@", jsonInput); | |
[[AWSCloudLogic sharedInstance] invokeFunction:functionName withParameters:parameters | |
withCompletionBlock:^(id result, NSError *error) { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self.activityIndicator stopAnimating]; | |
if (error != nil) { | |
UIAlertView *alert = | |
[[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"DISMISS" otherButtonTitles:nil]; | |
[alert show]; | |
} else { | |
self.instanceStatusLabel.text = @"インスタンスステータス:running"; | |
self.instanceStatus = @"running"; | |
} | |
}); | |
}]; | |
} else { | |
[self.activityIndicator stopAnimating]; | |
} | |
}]; | |
} else { | |
// 指紋認証を使えない端末の処理 | |
// 指紋認証を使える端末だが、ユーザーが指紋認証機能をオフにしているケースの処理 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment