-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
AppDelegate.m
129 lines (117 loc) · 4.61 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "AppDelegate.h"
#import "MainViewController.h"
#import "UIViewController+Alerts.h"
// [START auth_import]
@import Firebase;
// [END auth_import]
// [START google_import]
@import GoogleSignIn;
// [END google_import]
@import FBSDKCoreKit;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// [START firebase_configure]
// Use Firebase library to configure APIs
[FIRApp configure];
// [END firebase_configure]
// [START setup_gidsignin]
[GIDSignIn sharedInstance].clientID = [FIRApp defaultApp].options.clientID;
[GIDSignIn sharedInstance].delegate = self;
// [END setup_gidsignin]
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
// [START new_delegate]
- (BOOL)application:(nonnull UIApplication *)application
openURL:(nonnull NSURL *)url
options:(nonnull NSDictionary<NSString *, id> *)options {
// [END new_delegate]
return [self application:application
openURL:url
// [START new_options]
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
// [END new_options]
// [START old_delegate]
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// [END old_delegate]
if ([self handlePasswordlessSignInWithLink:url]) {
return YES;
}
if ([[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation]) {
return YES;
}
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
// [START old_options]
sourceApplication:sourceApplication
annotation:annotation];
}
// [END old_options]
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
#else
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler {
#endif
return [self handlePasswordlessSignInWithLink:userActivity.webpageURL];
}
- (BOOL)handlePasswordlessSignInWithLink:(nonnull NSURL*)url {
NSString *link = url.absoluteString;
// [START is_signin_link]
if ([[FIRAuth auth] isSignInWithEmailLink:link]) {
// [END is_signin_link]
[NSUserDefaults.standardUserDefaults setObject:link forKey:@"Link"];
[(UINavigationController*)_window.rootViewController popToRootViewControllerAnimated:NO];
[_window.rootViewController.childViewControllers[0] performSegueWithIdentifier:@"passwordless" sender:nil];
return YES;
}
return NO;
}
// [START headless_google_auth]
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error {
// [START_EXCLUDE]
MainViewController *controller = (MainViewController*) [GIDSignIn sharedInstance].uiDelegate;
// [END_EXCLUDE]
if (error == nil) {
// [START google_credential]
GIDAuthentication *authentication = user.authentication;
FIRAuthCredential *credential =
[FIRGoogleAuthProvider credentialWithIDToken:authentication.idToken
accessToken:authentication.accessToken];
// [END google_credential]
// [START_EXCLUDE]
[controller firebaseLoginWithCredential:credential];
// [END_EXCLUDE]
} else {
// [START_EXCLUDE]
[controller showMessagePrompt:error.localizedDescription];
// [END_EXCLUDE]
}
}
// [END headless_google_auth]
@end