0

I'm trying to adopt Facebook login process for my application goals. After successful Facebook login, I want to send a User to another View. For this reason, I'm using PerformSegue in UserLoginManager class, but always get the same issue in the AppDelegate file: Thread 1: "Receiver (<Leeeeeds.UserLoginManager: 0x7f9015010010>) has no segue with identifier 'gonext'"* (spelling for the identifier is correct, I've checked it thousands of times).*

At the same time, in debug console I see: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<Leeeeeds.UserLoginManager: 0x7f9015010010>) has no segue with identifier 'gonext''terminating with uncaught exception of type NSException CoreSimulator 802.6.1 - Device: iPhone 11

Here is my AppDelegate code:

import UIKit
import FacebookCore
import FacebookLogin


@main

class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        ApplicationDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )
        return true
    }
    
    func application(
        _ app: UIApplication,
        open url: URL,
        options: [UIApplication.OpenURLOptionsKey : Any] = [:]
    ) -> Bool {
        ApplicationDelegate.shared.application(
            app,
            open: url,
            sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
            annotation: options[UIApplication.OpenURLOptionsKey.annotation]
        )
    }
}

And my UserLoginManager class:

import Foundation
import FacebookLogin

let loginManager = LoginManager()

class UserLoginManager: UIViewController {
    func facebookLogin() {
        loginManager.logIn(permissions: [.publicProfile, .email], viewController: nil) { loginResult in
            switch loginResult {
            case .failed(let error):
                print(error)
            case .cancelled:
                print("User cancelled login.")
            case .success(let grantedPermissions, let declinedPermissions, let accessToken):
                self.performSegue(withIdentifier: "gonext", sender: self)
                print("Logged in! \(grantedPermissions) \(declinedPermissions) \(accessToken)")
                GraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name"]).start(completionHandler: { (connection, result, error) -> Void in
                    if (error == nil){
                        let fbDetails = result as! NSDictionary
                        print(fbDetails)
                    }
                })
            }
        }
    }
}

Here is my ViewController:

import UIKit
import FacebookLogin

class ViewController: UIViewController {
    
    var fbmanager = UserLoginManager()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    @IBAction func facebook(_ sender: UIButton) {
        fbmanager.facebookLogin()
    }

}

Thanks for any advice!

  • How is created `UserLoginManager`? How is it shown? Do you have somewhere in your code `UserLoginManager()`? – Larme Aug 31 '22 at 09:34
  • Yes, I'm using an instance of UserLoginManager() for my custom login button. Sorry, I'm new in coding and didn't get first two questions :( – Mykyta Yarovoi Aug 31 '22 at 09:43
  • You have `UserLoginManager()` in your code? Where? Could you print `self.storyboard` just before the `self.performSegue(...)`? – Larme Aug 31 '22 at 09:44
  • Please, check my ViewController code, maybe it makes any sense. Print `self.storyboard` haven't given any changes, only exclamation mark with info: Expression of type 'UIStoryboard?' is unused – Mykyta Yarovoi Aug 31 '22 at 09:55
  • " Print self.storyboard haven't given any changes" Well, it's not about solving, it's about checking its value. I guess it was nil, no? And seeing `var fbmanager = UserLoginManager()`, I know it was nil. The issue is that you are creating with `UserLoginManager()` a new instance of `UserLoginManager`, but it's not associated with a Storyboard, with the Storyboard you want. You need to initialize it with the target storyboard. Look how to. – Larme Aug 31 '22 at 09:57
  • Thank you so much for answers and patience. Could you please give me a little bit more hints how can i deal with it? – Mykyta Yarovoi Aug 31 '22 at 10:03
  • https://stackoverflow.com/questions/24035984/instantiate-and-present-a-viewcontroller-in-swift – Larme Aug 31 '22 at 10:14
  • `UserLoginManager` is even really a view controller. You have inherited it from `UIViewController` (presumably because otherwise you got an error when you tried to call `performSegue` but this class doesn't have any views and isn't presented in the view controller hierarchy. What your want to do is pass a completion closure to `facebookLogin` and have that function invoke it with the result. In the closure (which executes in your `ViewController` you can then perform the segue. – Paulw11 Aug 31 '22 at 12:12
  • @Paulw11 Thank you so much for answer. Could you please provide a real example referring to my code above. I appreciate your time, but I'm really new in Swift :(( – Mykyta Yarovoi Aug 31 '22 at 12:43

0 Answers0