Bläddra i källkod

Simulate challenge fetch and assertion generation delay.

Peter Andrews 3 år sedan
förälder
incheckning
511f1cc002

+ 27 - 22
Samples/Swift/DaysUntilBirthday/Shared/Services/GoogleSignInAuthenticator.swift

@@ -41,36 +41,41 @@ final class GoogleSignInAuthenticator: ObservableObject {
   /// Signs in the user based upon the selected account.'
   /// - note: Successful calls to this will set the `authViewModel`'s `state` property.
   func signIn() {
+    let challengeDelay = 0.200;
+    let assertionDelay = 0.160;
+    let totalDelay = challengeDelay + assertionDelay;
+    DispatchQueue.main.asyncAfter(deadline: .now() + totalDelay) {
 #if os(iOS)
-    guard let rootViewController = UIApplication.shared.windows.first?.rootViewController else {
-      print("There is no root view controller!")
-      return
-    }
-
-    GIDSignIn.sharedInstance.signIn(with: configuration,
-                                    presenting: rootViewController) { user, error in
-      guard let user = user else {
-        print("Error! \(String(describing: error))")
+      guard let rootViewController = UIApplication.shared.windows.first?.rootViewController else {
+        print("There is no root view controller!")
         return
       }
-      self.authViewModel.state = .signedIn(user)
-    }
 
-#elseif os(macOS)
-    guard let presentingWindow = NSApplication.shared.windows.first else {
-      print("There is no presenting window!")
-      return
-    }
+      GIDSignIn.sharedInstance.signIn(with: self.configuration,
+                                      presenting: rootViewController) { user, error in
+        guard let user = user else {
+          print("Error! \(String(describing: error))")
+          return
+        }
+        self.authViewModel.state = .signedIn(user)
+      }
 
-    GIDSignIn.sharedInstance.signIn(with: configuration,
-                                    presenting: presentingWindow) { user, error in
-      guard let user = user else {
-        print("Error! \(String(describing: error))")
+#elseif os(macOS)
+      guard let presentingWindow = NSApplication.shared.windows.first else {
+        print("There is no presenting window!")
         return
       }
-      self.authViewModel.state = .signedIn(user)
-    }
+
+      GIDSignIn.sharedInstance.signIn(with: self.configuration,
+                                      presenting: presentingWindow) { user, error in
+        guard let user = user else {
+          print("Error! \(String(describing: error))")
+          return
+        }
+        self.authViewModel.state = .signedIn(user)
+      }
 #endif
+    }
   }
 
   /// Signs out the current user.