-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathAppDelegate.m
executable file
·45 lines (37 loc) · 2.12 KB
/
AppDelegate.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
#import "AppDelegate.h"
#import "LoginViewController.h"
#import "SuccessViewController.h"
#import "CleverSDK.h"
@interface AppDelegate ()
@property (nonatomic, strong) UINavigationController* navigationController;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
LoginViewController *vc = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = self.navigationController;
// Start the CleverSDK with your client
// Do not forget to replace CLIENT_ID with your client_id
[CleverSDK startWithClientId:@"CLIENT_ID" RedirectURI:@"http://example.com" successHandler:^(NSString *code, BOOL validState) {
SuccessViewController *vc = [[SuccessViewController alloc] initWithCode:code];
[self.navigationController popToRootViewControllerAnimated:NO];
[self.navigationController pushViewController:vc animated:YES];
} failureHandler:^(NSString *errorMessage) {
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:@"Error"
message: errorMessage
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
[vc presentViewController:alert animated:YES completion:nil];
[self.navigationController popToRootViewControllerAnimated:YES];
return;
}];
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
return [CleverSDK handleURL:[userActivity webpageURL]];
}
@end