Вход в систему / Segue для iOS 13.2 с использованием Firebase - PullRequest
0 голосов
/ 05 ноября 2019

Я пытаюсь реализовать Вход в Google для моего iOS 13.2 приложения с использованием Firebase . Как реализовать segue со страницы входа на HomeScreen (a ViewController), как только пользователь войдет в систему.

Существует метод, прикрепленный к AppDelegate - GIDSignInDelegate, который сообщаетмы, когда пользователь вошел в систему. Я хочу segue в этот момент на домашний экран. Этот код находится в AppDelegate, и я не могу использовать AppDelegate's window для загрузки из StoryBoard из-за нового поведения SceneDelegate.

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        if (error == nil) {
          // Perform any operations on signed in user here.
          // ...
            print("User signed in")

            //place to perform segue
            //write code for segue here

        }
        else {
          print("\(error.localizedDescription)")
        }
        if user != nil
        {
        guard let authentication = user.authentication else { return }
          let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
                                                            accessToken: authentication.accessToken)
          // ...
        Auth.auth().signIn(with: credential) { (authResult, error) in
          if let error = error {
            // ...
            return
          }
          // User is signed in
          // ...          
        }
        }       
    }   

Ожидаемый результат: https://stackoverflow.com/a/27136455/6311566, но это не работает в iOS 13.2

1 Ответ

0 голосов
/ 05 ноября 2019

OLD WAY

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        let rootVC = window?.rootViewController

        return true
    }

Это потому, что AppDelegate.swift больше не имеет свойства окна. Теперь вы должны использовать SceneDelegate.swift для изменения контроллера корневого представления. Как показано в этом примере:

ЧТО ДЕЛАТЬ СЕЙЧАС

Теперь вы перенесете этот код в файл SceneDelegate Swift вашего приложения:

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

     var window: UIWindow?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
         // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
         // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
         // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let _ = (scene as? UIWindowScene) else { return }

        // Create the root view controller as needed
        let vc = ViewController()
        let nc = UINavigationController(rootViewController: vc)

        // Create the window. Be sure to use this initializer and not the frame one.
        let win = UIWindow(windowScene: winScene) 
        win.rootViewController = nc
        win.makeKeyAndVisible()
        window = win
    }

    // ... the rest of SceneDelegate
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...