whose view is not in the window hierarchy Facebook Login - ios

I have this warning I don't understand where is my error in my code
using code 7.2 and iOS 9.2
Error:
warning: Attempt to present < VidcustCustomAppIos.VCTabBarController:
0x7ff838f50790 > on < FBSDKContainerViewController: 0x7ff838d8ceb0 >
whose view is not in the window hierarchy!
#IBAction func facebookLoginDidTouch(sender: AnyObject) {
let loginManager = FBSDKLoginManager()
loginManager.logInWithReadPermissions(["public_profile", "email"], fromViewController: self) { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
if (result.isCancelled) {
print("Cancelled")
} else {
print("Logged in")
let token = FBSDKAccessToken.currentAccessToken()
VCClusterManager.sharedInstance.connectWithFacebook(token.tokenString, completion: { (isConnected, error) -> () in
if error == nil && isConnected == true {
self.performSegueWithIdentifier(self.segueIdentifier, sender: nil)
}
})
}
}
}

This is not with the case of Facebook Login
You will get this warning when performing a segue from a view controller that is embedded in container. The solution is to use segue from the parent of container, not from container's view controller.

Error:
Developers can receive this warning when performing a segue from a view controller that is embedded in container.
Solution:
Use segue from the parent of container, not from container's view controller (eg. back button, next button or any buttons that you want to perform an action to transition to another view controller)

Related

Calling Auth.auth().signOut() automatically dismisses the ViewController

The current view controller gets dismissed as soon as I call the signOut method by pressing the button. The signing out process however is successful. (I'm using the FirebaseAuth SDK.)
Here is my code:
#IBAction func logoutPressed(_ sender: Any) {
do {
try Auth.auth().signOut()
} catch let signOutError as NSError {
showAlertSaying(
title: "Fehler beim ausloggen",
message: "Ein Fehler ist aufgetreten",
view: self
)
print ("Error signing out: %#", signOutError)
}
}
Is there any way to prevent that the view controller gets dismissed?
It appears that your storyboard button is linked to another action in addition to this
#IBAction func logoutPressed(_ sender: Any) {
which has a dismiss / pop action
This scenario happens when you copy elements in storyboard

UserDefaults Auto-Login isn't Working

So when the user first opens my app they will see a view with a button to proceed with logging in or registering. In my Login view, I have a button handler (attached via action) which is called when a user presses a login button. Despite me using UserDefaults to store logged in state, my app does not go straight to my Dashboard view automatically. Any ideas why?
// Firebase auth in doLogin action (Login VC)
Auth.auth().signIn(withEmail: un, password: pw)
{
(resp, err) in if (err == nil && resp != nil)
{
if (resp!.user.isEmailVerified)
{
// segue from Login VC to Dashboard VC will be exectuted
self.performSegue(withIdentifier: "loggedin", sender: nil)
// store the logged in state as true for the future
UserDefaults.standard.set(true, forKey: "loggedin")
UserDefaults.standard.synchronize()
}
}
}
Here is the code for the Main view controller to determine if it should proceed directly to dashboard.
func loggedIn() -> Bool {
// determine if the user is still logged into the app
return UserDefaults.standard.bool(forKey: "loggedin")
}
override func viewDidLoad() {
super.viewDidLoad()
if (loggedIn())
{
// logged in, return to the dashboard view controller
performSegue(withIdentifier: "persisted", sender: nil)
}
}
I've tried using print statements and either the loggedIn function isn't being executed for whatever reason or the console is just too flooded with Firebase debug log statements to even see these.
You have to embed your main view controller inside a UINavigationController to make the persisted segue work.

Swift Firebase login

I'm having a problem where every time I enter the right credentials, it brings me to one view controller then opens up the same view controller again even though I only have the login viewer controller linked to one view controller. If I don't enter the right credentials it still brings me into the linked view controller. Here is the code.
EDIT: Using a push segue(show)
#IBAction func loginTapped(_ sender: Any) {
if let Email = userEmail.text, let Pass = userPassword.text{
Auth.auth().signIn(withEmail: Email, password: Pass, completion: { (user, error) in
if error != nil{
print("incorrect")
}
else{
if error == nil{
self.performSegue(withIdentifier: "loginPage", sender: self)
print("correct")
}
}
})
}
}
I don't know if you've fixed your problem, but check your storyboard. Sounds like you have a segue connected from the button to the next ViewController which would result in pressing the button and it'll always push that ViewController.
To do this easily just see if you have a segue connected from the button to your destination ViewController in your MainStoryboard.

Perform segue not working inside api call

I have login page that use API call for checking credentials at the end i present main page as modal with performSegue like this :
#IBAction func loginPressed(sender: UIButton) {
ApiHelper.userService { (service) -> Void in
let query = GTLUserController.queryForLoginUser(email,password)
service.executeQuery(query) { (ticket: GTLServiceTicket!, object: AnyObject!, error: NSError!) -> Void in
if(error != nil){
return
}
//Code...
self.performSegueWithIdentifier("mainSegue", sender: self)
}
}
}
The segue work fine when i launch the app for the first time, but when i terminate the app (using swipe) and login again the segue is not working i see the main page for 1s then it back to login.
N.B : the segue work fine when i use it outside the API call
Thank's in advance
Never update the UI on a background thread, instead perform the segue on the main thread like so
dispatch_async(dispatch_get_main_queue()) {
self.performSegueWithIdentifier("mainSegue", sender: self)
}

Prevent Segue Transition in Login Swift/Parse

I have a login view controller where it should prevent the user from transition to the next view controller via a segue called "toMasterTab". I think the logic might be wrong - if the user entered the correct credentials and is not empty, it transitions fine, but if the user entered no credentials (nil) and entered the wrong credentials, then it should prevent the segue. So far, I can only get the UIAlertView to pop up, but other than that, I can't solve this...
#IBAction func loginButton(sender: AnyObject) {
let RedPlanetUser = RPUsername.text
let RedPlanetUserPassword = RPUserPassword.text
PFUser.logInWithUsernameInBackground(RedPlanetUser!, password: RedPlanetUserPassword!) {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
// Do stuff after successful login
self.performSegueWithIdentifier("toMasterTab", sender: self)
print("User logged in successfully")
} else {
// Login failed
print("User log in failed")
// Present alert
var alert = UIAlertView(title: "Login Failed",
message: "The username and password do not match.",
delegate: self,
cancelButtonTitle: "Try Again")
alert.show()
func shouldPerformSegueWithIdentifier(identifier: String!, object: AnyObject) -> Bool {
let identifier = "toMasterTab"
// prevent segue
return false
}
}
}
}
I believe you should be overriding the
override func shouldPerformSegueWithIdentifier
The problem was that the segue was connected to the button, so it automatically performed the segue even when the conditions were NOT met. I connected the segue from VC1 to VC2 and used the following code when the conditions were met, and didn't call the segue when the conditions were erroneous:
self.performSegueWithIdentifier("toMasterTab", sender: self)

Resources