Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.

Commit ac9fbc2

Browse files
committed
update to GSI 5.0 pod
1 parent e291bf2 commit ac9fbc2

File tree

8 files changed

+465
-60
lines changed

8 files changed

+465
-60
lines changed

ios/signin/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use_frameworks!
2-
platform :ios, '7.0'
2+
platform :ios, '8.0'
33
pod 'GoogleSignIn'
44

55
target 'SignInExample' do

ios/signin/SignInExample.xcodeproj/project.pbxproj

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
10A034B61E039F1900A667F0 /* SignInExampleTests */,
157157
4BC032DF1ACF33B70092326A /* Products */,
158158
E27D599993EDB54E213FA076 /* Frameworks */,
159+
72A0AD6FEF1A09A1A7F1472D /* Pods */,
159160
);
160161
sourceTree = "<group>";
161162
};
@@ -192,6 +193,13 @@
192193
name = "Supporting Files";
193194
sourceTree = "<group>";
194195
};
196+
72A0AD6FEF1A09A1A7F1472D /* Pods */ = {
197+
isa = PBXGroup;
198+
children = (
199+
);
200+
path = Pods;
201+
sourceTree = "<group>";
202+
};
195203
E27D599993EDB54E213FA076 /* Frameworks */ = {
196204
isa = PBXGroup;
197205
children = (
@@ -301,6 +309,7 @@
301309
developmentRegion = English;
302310
hasScannedForEncodings = 0;
303311
knownRegions = (
312+
English,
304313
en,
305314
Base,
306315
);
@@ -456,7 +465,7 @@
456465
SDKROOT = iphoneos;
457466
SWIFT_OBJC_BRIDGING_HEADER = "";
458467
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
459-
SWIFT_VERSION = 3.0;
468+
SWIFT_VERSION = 5.0;
460469
VALID_ARCHS = "armv7 armv7s arm64";
461470
};
462471
name = Debug;
@@ -479,7 +488,7 @@
479488
PRODUCT_NAME = "$(TARGET_NAME)";
480489
SDKROOT = iphoneos;
481490
SWIFT_OBJC_BRIDGING_HEADER = "";
482-
SWIFT_VERSION = 3.0;
491+
SWIFT_VERSION = 5.0;
483492
VALID_ARCHS = "armv7 armv7s arm64";
484493
};
485494
name = Release;
@@ -610,6 +619,7 @@
610619
10A034BD1E039F1900A667F0 /* Release */,
611620
);
612621
defaultConfigurationIsVisible = 0;
622+
defaultConfigurationName = Release;
613623
};
614624
4B97B2721AD7145E0036DD6C /* Build configuration list for PBXNativeTarget "SignInExampleSwift" */ = {
615625
isa = XCConfigurationList;

ios/signin/SignInExample/AppDelegate.m

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,41 @@ - (BOOL)application:(UIApplication *)application
2929
}
3030
// [END didfinishlaunching]
3131

32+
// [START openurl_new]
33+
- (BOOL)application:(UIApplication *)app
34+
openURL:(NSURL *)url
35+
options:(NSDictionary<NSString *, id> *)options {
36+
return [[GIDSignIn sharedInstance] handleURL:url];
37+
}
38+
// [END openurl_new]
39+
3240
// [START openurl]
3341
- (BOOL)application:(UIApplication *)application
3442
openURL:(NSURL *)url
3543
sourceApplication:(NSString *)sourceApplication
3644
annotation:(id)annotation {
37-
return [[GIDSignIn sharedInstance] handleURL:url
38-
sourceApplication:sourceApplication
39-
annotation:annotation];
45+
return [[GIDSignIn sharedInstance] handleURL:url];
4046
}
4147
// [END openurl]
4248

4349
// [START signin_handler]
4450
- (void)signIn:(GIDSignIn *)signIn
4551
didSignInForUser:(GIDGoogleUser *)user
4652
withError:(NSError *)error {
53+
if (error != nil) {
54+
if (error.code == kGIDSignInErrorCodeHasNoAuthInKeychain) {
55+
NSLog(@"The user has not signed in before or they have since signed out.");
56+
} else {
57+
NSLog(@"%@", error.localizedDescription);
58+
}
59+
// [START_EXCLUDE silent]
60+
[[NSNotificationCenter defaultCenter]
61+
postNotificationName:@"ToggleAuthUINotification"
62+
object:nil
63+
userInfo:nil];
64+
// [END_EXCLUDE]
65+
return;
66+
}
4767
// Perform any operations on signed in user here.
4868
NSString *userId = user.userID; // For client-side use only!
4969
NSString *idToken = user.authentication.idToken; // Safe to send to the server

ios/signin/SignInExample/ViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@import GoogleSignIn;
1919

2020
// [START viewcontroller_interfaces]
21-
@interface ViewController : UIViewController <GIDSignInUIDelegate>
21+
@interface ViewController : UIViewController
2222
// [END viewcontroller_interfaces]
2323

2424
// [START viewcontroller_vars]

ios/signin/SignInExample/ViewController.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ @implementation ViewController
2121
- (void)viewDidLoad {
2222
[super viewDidLoad];
2323

24-
// TODO(developer) Configure the sign-in button look/feel
24+
[GIDSignIn sharedInstance].presentingViewController = self;
2525

26-
[GIDSignIn sharedInstance].uiDelegate = self;
26+
// Automatically sign in the user.
27+
[[GIDSignIn sharedInstance] restorePreviousSignIn];
2728

28-
// Uncomment to automatically sign in the user.
29-
//[[GIDSignIn sharedInstance] signInSilently];
3029
// [START_EXCLUDE silent]
3130
[[NSNotificationCenter defaultCenter]
3231
addObserver:self

ios/signin/SignInExampleSwift/AppDelegate.swift

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,74 +20,75 @@ import GoogleSignIn
2020
// [START appdelegate_interfaces]
2121
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
2222

23-
// [END appdelegate_interfaces]
23+
// [END appdelegate_interfaces]
2424
var window: UIWindow?
2525

2626
// [START didfinishlaunching]
2727
func application(_ application: UIApplication,
28-
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
29-
// Initialize sign-in
30-
GIDSignIn.sharedInstance().clientID = "YOUR_CLIENT_ID"
31-
GIDSignIn.sharedInstance().delegate = self
28+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
29+
// Initialize sign-in
30+
GIDSignIn.sharedInstance().clientID = "YOUR_CLIENT_ID"
31+
GIDSignIn.sharedInstance().delegate = self
3232

33-
return true
33+
return true
3434
}
3535
// [END didfinishlaunching]
3636

3737
// [START openurl]
3838
func application(_ application: UIApplication,
39-
open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
40-
return GIDSignIn.sharedInstance().handle(url,
41-
sourceApplication: sourceApplication,
42-
annotation: annotation)
39+
open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
40+
return GIDSignIn.sharedInstance().handle(url)
4341
}
4442
// [END openurl]
4543

44+
// [START openurl_new]
4645
@available(iOS 9.0, *)
47-
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
48-
return GIDSignIn.sharedInstance().handle(url,
49-
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
50-
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
46+
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
47+
return GIDSignIn.sharedInstance().handle(url)
5148
}
49+
// [END openurl_new]
5250

5351
// [START signin_handler]
5452
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
55-
withError error: Error!) {
56-
if let error = error {
57-
print("\(error.localizedDescription)")
58-
// [START_EXCLUDE silent]
59-
NotificationCenter.default.post(
60-
name: Notification.Name(rawValue: "ToggleAuthUINotification"), object: nil, userInfo: nil)
61-
// [END_EXCLUDE]
53+
withError error: Error!) {
54+
if let error = error {
55+
if (error as NSError).code == GIDSignInErrorCode.hasNoAuthInKeychain.rawValue {
56+
print("The user has not signed in before or they have since signed out.")
6257
} else {
63-
// Perform any operations on signed in user here.
64-
let userId = user.userID // For client-side use only!
65-
let idToken = user.authentication.idToken // Safe to send to the server
66-
let fullName = user.profile.name
67-
let givenName = user.profile.givenName
68-
let familyName = user.profile.familyName
69-
let email = user.profile.email
70-
// [START_EXCLUDE]
71-
NotificationCenter.default.post(
72-
name: Notification.Name(rawValue: "ToggleAuthUINotification"),
73-
object: nil,
74-
userInfo: ["statusText": "Signed in user:\n\(fullName)"])
75-
// [END_EXCLUDE]
58+
print("\(error.localizedDescription)")
7659
}
60+
// [START_EXCLUDE silent]
61+
NotificationCenter.default.post(
62+
name: Notification.Name(rawValue: "ToggleAuthUINotification"), object: nil, userInfo: nil)
63+
// [END_EXCLUDE]
64+
return
65+
}
66+
// Perform any operations on signed in user here.
67+
let userId = user.userID // For client-side use only!
68+
let idToken = user.authentication.idToken // Safe to send to the server
69+
let fullName = user.profile.name
70+
let givenName = user.profile.givenName
71+
let familyName = user.profile.familyName
72+
let email = user.profile.email
73+
// [START_EXCLUDE]
74+
NotificationCenter.default.post(
75+
name: Notification.Name(rawValue: "ToggleAuthUINotification"),
76+
object: nil,
77+
userInfo: ["statusText": "Signed in user:\n\(fullName!)"])
78+
// [END_EXCLUDE]
7779
}
7880
// [END signin_handler]
7981

8082
// [START disconnect_handler]
8183
func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!,
82-
withError error: Error!) {
83-
// Perform any operations when the user disconnects from app here.
84-
// [START_EXCLUDE]
85-
NotificationCenter.default.post(
86-
name: Notification.Name(rawValue: "ToggleAuthUINotification"),
87-
object: nil,
88-
userInfo: ["statusText": "User has disconnected."])
89-
// [END_EXCLUDE]
84+
withError error: Error!) {
85+
// Perform any operations when the user disconnects from app here.
86+
// [START_EXCLUDE]
87+
NotificationCenter.default.post(
88+
name: Notification.Name(rawValue: "ToggleAuthUINotification"),
89+
object: nil,
90+
userInfo: ["statusText": "User has disconnected."])
91+
// [END_EXCLUDE]
9092
}
9193
// [END disconnect_handler]
92-
9394
}

ios/signin/SignInExampleSwift/ViewController.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import GoogleSignIn
1919
// Match the ObjC symbol name inside Main.storyboard.
2020
@objc(ViewController)
2121
// [START viewcontroller_interfaces]
22-
class ViewController: UIViewController, GIDSignInUIDelegate {
22+
class ViewController: UIViewController {
2323
// [END viewcontroller_interfaces]
2424

2525
// [START viewcontroller_vars]
@@ -33,12 +33,11 @@ class ViewController: UIViewController, GIDSignInUIDelegate {
3333
override func viewDidLoad() {
3434
super.viewDidLoad()
3535

36-
GIDSignIn.sharedInstance().uiDelegate = self
36+
GIDSignIn.sharedInstance()?.presentingViewController = self
3737

38-
// Uncomment to automatically sign in the user.
39-
//GIDSignIn.sharedInstance().signInSilently()
38+
// Automatically sign in the user.
39+
GIDSignIn.sharedInstance()?.restorePreviousSignIn()
4040

41-
// TODO(developer) Configure the sign-in button look/feel
4241
// [START_EXCLUDE]
4342
NotificationCenter.default.addObserver(self,
4443
selector: #selector(ViewController.receiveToggleAuthUINotification(_:)),
@@ -72,7 +71,7 @@ class ViewController: UIViewController, GIDSignInUIDelegate {
7271

7372
// [START toggle_auth]
7473
func toggleAuthUI() {
75-
if GIDSignIn.sharedInstance().hasAuthInKeychain() {
74+
if let _ = GIDSignIn.sharedInstance()?.currentUser?.authentication {
7675
// Signed in
7776
signInButton.isHidden = true
7877
signOutButton.isHidden = false

0 commit comments

Comments
 (0)