-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgoogle.ios.js
executable file
·124 lines (90 loc) · 3.99 KB
/
google.ios.js
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
var Application = require("@nativescript/core").Application
var Google = function(){
var scopes = [ "profile", "email" ]
// args = {scopes, shouldFetchBasicProfile, clientID}
Google.initSdk = function(args) {
args = args || {shouldFetchBasicProfile: true}
var signIn = GIDSignIn.sharedInstance();
signIn.shouldFetchBasicProfile = args.shouldFetchBasicProfile;
signIn.scopes = args.scopes || scopes;
if(args.kClientId)
signIn.clientID = args.clientID;
var delegate = this.createSignInDelegate();
signIn.delegate = delegate;
signIn.uiDelegate = delegate;
console.log("## initSdk")
}
Google.registerCallback = function(successCallback, failCallback){
this._successCallback = successCallback;
this._failCallback = failCallback;
}
Google.disconnect = function(){
GIDSignIn.sharedInstance().disconnect();
}
Google.logOut = function(){
GIDSignIn.sharedInstance().signOut();
}
Google.logIn = function(profileInfoCallback){
this._profileInfoCallback = profileInfoCallback
GIDSignIn.sharedInstance().signIn();
}
Google.isLoggedIn = function(){
return GIDSignIn.sharedInstance().hasAuthInKeychain()
}
Google.createSignInDelegate = function(){
var self = this
var MySignInDelegate = (function (_super) {
__extends(MySignInDelegate, _super);
function MySignInDelegate() {
_super.apply(this, arguments);
}
MySignInDelegate.prototype.signInDidSignInForUserWithError = function(signIn, user, error){
if(error){
self._failCallback('logIn')
}else{
try{
var user = {
userId: user.userID, // For client-side use only!
idToken: user.authentication.idToken, // Safe to send to the server
fullName: user.profile.name,
givenName: user.profile.givenName,
familyName: user.profile.familyName,
email: user.profile.email,
}
self._successCallback('logIn')
if(self._profileInfoCallback)
self._profileInfoCallback(user)
else
console.log("## set profileInfoCallback on login")
}catch(error){
this._failCallback(error)
}
}
}
MySignInDelegate.prototype.signInDidDisconnectWithUserWithError = function(signIn, user, error){
try{
if(error)
self._failCallback(error.localizedDescription)
else
self._successCallback('logOut')
}catch(error){
this._failCallback(error)
}
}
MySignInDelegate.prototype.signInWillDispatchError = function(signIn, error) {
}
MySignInDelegate.prototype.signInPresentViewController = function (signIn, viewController){
var uiview = applicationModule.ios.rootController;
uiview.presentViewControllerAnimatedCompletion(viewController, true, null);
}
MySignInDelegate.prototype.signInDismissViewController = function(signIn, viewController){
viewController.dismissViewControllerAnimatedCompletion(true, null);
}
MySignInDelegate.ObjCProtocols = [GIDSignInDelegate, GIDSignInUIDelegate];
return MySignInDelegate;
}(NSObject));
return new MySignInDelegate()
}
return Google
}
exports.Google = Google