Skip to content

Instantly share code, notes, and snippets.

@horike37
Created November 27, 2015 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horike37/ff3a7d2a2f373020cc8e to your computer and use it in GitHub Desktop.
Save horike37/ff3a7d2a2f373020cc8e to your computer and use it in GitHub Desktop.
startInstanceのLambdaを起動させるobjective-cのコード
- (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