Facebook認証でログイン後に、
別ストーリーボードのビューに遷移したいのですが、
FBログインしてから1秒後にクラッシュして、タイトルのThread 1: Fatal error: Can't form Range with upperBound < lowerBound
エラーが発生します。
この場合、下記↓の遷移メソッドは使用できないという事ですか?
let storyboard: UIStoryboard = UIStoryboard(name: "遷移先のSB名", bundle: nil)
let nextView = storyboard.instantiateInitialViewController()
self.present(nextView!, animated: true, completion: nil)
(AppDelegateです) import UIKit import Firebase import FirebaseAuth import GoogleSignIn import FBSDKCoreKit import RAMAnimatedTabBarController @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { FirebaseApp.configure() GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID GIDSignIn.sharedInstance().delegate = self FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) return true } func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { if let err = error { print("Failed to log into Google: ", err) return } print("Successfully logged into Google", user) guard let idToken = user.authentication.idToken else { return } guard let accessToken = user.authentication.accessToken else { return } let credentials = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: accessToken) Auth.auth().signIn(with: credentials, completion: { (user, error) in if let err = error { print("Failed to create a Firebase User with Google account: ", err) return } guard let uid = user?.uid else { return } print("Successfully logged into Firebase with Google", uid) }) } func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation]) GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation]) return handled } func applicationWillResignActive(_ application: UIApplication) { } func applicationDidEnterBackground(_ application: UIApplication) { } func applicationWillEnterForeground(_ application: UIApplication) { } func applicationDidBecomeActive(_ application: UIApplication) { } func applicationWillTerminate(_ application: UIApplication) { } }
(MainViewControllerです。このビューでログインします) import UIKit import Firebase import FirebaseAuth import GoogleSignIn import FBSDKCoreKit import FBSDKLoginKit import RAMAnimatedTabBarController class MainViewController: UIViewController, FBSDKLoginButtonDelegate, GIDSignInUIDelegate { override func viewDidLoad() { super.viewDidLoad() GIDSignIn.sharedInstance().uiDelegate = self setupFacebookButtons() setupGoogleButtons() } fileprivate func setupGoogleButtons() { //add google sign in button let googleButton = GIDSignInButton() googleButton.frame = CGRect(x: 16, y: 116 + 66, width: view.frame.width - 32, height: 50) view.addSubview(googleButton) } fileprivate func setupFacebookButtons() { let loginButton = FBSDKLoginButton() view.addSubview(loginButton) //frame's are obselete, please use constraints instead because its 2016 after all loginButton.frame = CGRect(x: 16, y: 50, width: view.frame.width - 32, height: 50) loginButton.delegate = self } func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) { print("Did log out of facebook") } //Gogleログイン func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) { // ... if error != nil { // ... return } guard let authentication = user.authentication else { return } let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken) // ... Auth.auth().signIn(with: credential) { (user, error) in if error != nil { // ... return } let storyboard: UIStoryboard = UIStoryboard(name: "RAMAnimatedTabBar", bundle: nil) let nextView = storyboard.instantiateInitialViewController() self.present(nextView!, animated: true, completion: nil) } } //FBログイン func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) { if error != nil { print(error) return } let accessToken = FBSDKAccessToken.current() guard let accessTokenString = accessToken?.tokenString else { return } let credentials = FacebookAuthProvider.credential(withAccessToken: accessTokenString) Auth.auth().signIn(with: credentials) { (user, error) in if error != nil { // ... return } let storyboard: UIStoryboard = UIStoryboard(name: "RAMAnimatedTabBar", bundle: nil) let nextView = storyboard.instantiateInitialViewController() self.present(nextView!, animated: true, completion: nil) // User is signed in // ... } } //各サインアップ画面へ @IBAction func toSignUpVC(_ sender: Any) { let storyboard: UIStoryboard = UIStoryboard(name: "SignUpView", bundle: nil) let nextView = storyboard.instantiateInitialViewController() present(nextView!, animated: true, completion: nil) } /* StoryboadでMailSignUpToFirstViewを引くため(戻るため)に必要 ボタン 戻る際の処理が特に必要ないのでメソッドは空です*/ @IBAction func BackStartView(segue: UIStoryboardSegue) { } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/01/14 03:45