-
Notifications
You must be signed in to change notification settings - Fork 22
/
ViewController.m
54 lines (41 loc) · 1.6 KB
/
ViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// ViewController.m
// HCaptcha_Objc_Example
//
// Copyright © 2022 HCaptcha. MIT License.
//
#import "ViewController.h"
#import "AppDelegate.h"
@import HCaptcha;
@import WebKit;
@interface ViewController ()
@property (weak, nonatomic) HCaptcha *hCaptcha;
@property (weak, nonatomic) WKWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
self.hCaptcha = appDelegate.hCaptcha;
[self.hCaptcha configureWebView:^(WKWebView * _Nonnull webView) {
webView.frame = self.view.bounds;
self.webView = webView;
}];
[self.hCaptcha onEvent:^(enum HCaptchaEvent event, id _Nullable _) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"On Event" message: [NSString stringWithFormat:@"%ld", event, nil] preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated: YES completion:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:nil];
});
}];
}];
}
- (IBAction) didPressButton:(UIButton *)button {
[self.hCaptcha validateOn:self.view resetOnError:NO completion:^(HCaptchaResult *result) {
NSError *error = nil;
NSString *token = [result dematerializeAndReturnError: &error];
NSLog(@"DONE token:%@ error:%@", token, [error description]);
[self.webView removeFromSuperview];
}];
}
@end