Is Firebase unauth() codes correct? - ios

I use Firebase for my app. When I segue back from a page to Login page and in prepareForSegue to logout the user, the page DOES go to login page but comes back to former page automatically right away. I want to make sure codes for logout are correct. Here are the codes:. Ref_URLBASE is my app ref in Firebase.
#IBAction func backBtnPressed(sender: AnyObject) {
self.performSegueWithIdentifier("toLoginPage", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "toLoginPage" {
Ref_URLBASE.unauth()
}

It is likely code in your login page controller causing an autologin if you have implemented keychain access for username/password. Make sure this gets cleared after logout so that it doesn't auto log them in right after they logged out.

Related

Conditionally show settings page?

I want to check if the user is a moderator before displaying a certain page in my settings. Here's how my storyboard is laid out:
When the user taps the "Invite users to pack" I want to check if a certain variable is true before pushing the view.
The problem is that if I hook up the cell to the UIViewController to its right then it automatically transitions when the cell is pressed. How would I implement some sort of code like?
if (isMod == true) {
// Show page
} else {
print("ACCESS DENIED")
}
If you're using segue, check it in override func prepare(for segue: UIStoryboardSegue, sender: Any?) in viewClass with tableView. Or you're using code to push (to navigationController), you can check before .pushViewController(viewController:, animated:)

Swift 3: PerformSegue WithIdentifier Not Displaying View Controller, No Errors

When I execute the line below, my destination view controller is not visually presented but there are no errors in the log:
performSegue (withIdentifier: "DetailsViewController", sender: self)
Let's step back from a problem. Imagine my successful setup: ViewController is loaded and upon some user action the above line would actually open a new DetailsViewController. I tested - everything works as expected - so I know it works.
But the problem presenting DetailsViewController begins when I decide to implement some third party framework by adding a CamViewController to my ViewController and perform segue upon element tap inside CamViewController, then delegate method passing this action back to ViewController from which I would open DetailsViewController. With this architecture setup I get no errors in a log but visually nothing is opening. No DetailsViewController ever presented.
A bit more details of architecture:
ViewController presents CamViewController with line self.present(camViewController, animated: true, completion: nil)
CamViewController implements a protocol to call some method on user action
ViewController conforms to CamViewController protocol and delegate method successfully runs on user action (log shows it is working)
Calling DetailsViewController with segue identifier is executed successfully performSegue (withIdentifier: "DetailsViewController", sender: self) but DetailsViewController is never displayed on screen.
This method below prints prepare for segue Optional("DetailsViewController") which sounds correct.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("prepare for segue \(segue.identifier)")
}
I also tried adding super.performSegue - no luck
First I would change your segue code to something more like this.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "DetailsViewController"){
print("prepare for segue DetailsViewController")
} else {
print("prepare for segue other")
}
}

Swift: Trouble getting rid of "dim"

I have been following this tutorial: http://www.totem.training/swift-ios-tips-tricks-tutorials-blog/ux-chops-dim-the-lights
However I have edited it slightly so that I can specify different Segues and also do it programmatically.
The problem occurs when I close the popped up view. When I close it, the background dim stays there:
What I did to the project files:
files: (https://github.com/TotemTraining/DimBackground.git)
1) Deleted the Segue that was there
2) Created an IBAction for the button named clickedButton
3) Created new Segue from first VC to second Named the Segue testSegue
4) Added this code for the IBAction:
#IBAction func clickedButton(sender: AnyObject) {
performSegueWithIdentifier("testSegue", sender: self)
}
5) Changed the prepareForSegue to:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "testSegue") {
dim(.In, alpha: dimLevel, speed: dimSpeed)
}
}
Now, When I run it, it shows the popup the desired way however when I click the close it removed it but leaves the "Dim" there. Can anyone see why?
The view is going to have several segues from it and I only want a few of them to have this "dim" effect.
Edit:
If I take out the if (segue.identifier == "testSegue") so its now:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//if (segue.identifier == "testSegue") {
dim(.In, alpha: dimLevel, speed: dimSpeed)
//}
}
it works as desired, so is it something to do with that?
It sounds like your unwind isn't getting called in order to dim out. Have you set a breakpoint to make sure? Also, if you are using Xcode 8, there was a weird bug with unwind segue names. They automatically got appended with "WithSegue:" at the end of them, so double check that it is labeled correctly in Interface Builder.

Remove tab from TabBarController with different users iOS Swift

As you seen in the picture above, there're one login screen, tab bar will appear after login successfully.
What I want to do is, let say there are two different user such as Admin and Staff, they have different login credentials, the Admin login will show all the tab at the bottom, however, the Staff login can just see the first tab. How could I do that? Any idea or code example to refer?
In login screen you can override prepareForSegue as shown below
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let destinationTabBar = segue.destinationViewController as? UITabBarController {
if (!isAdmin) {
destinationTabBar.viewControllers?.removeAtIndex(adminScreenIndex)
}
}
}
In the code above, you check if the user is admin in prepareForSegue method for tab bar controller. If the user is not admin, you remove needed screen (by adminScreenIndex index)

Unwind Segue using performSegueWithIdentifier - Doesn't work - Swift 2.1

I am trying to unwind in my button click, after receiving response.
LoginController
#IBAction func SignInPressed(sender: AnyObject) {
if (onSuccess) {
performSegueWithIdentifier("unwindToGlobal", sender: AnyObject?())
}
}
and this is where it comes from (GlobalController).
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if (segue.identifier == "globalToLogin")
{
NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
let loginController = segue.destinationViewController as? LoginController
})
}
}
This one works and as soon as I enter the app (GlobalController is the starting view), I get directed to Login Page. However, when I click on the login button on LoginController, unfortunately it doesn't unwind.
When I try to remove these connections and ctrl + drag button to exit, it just doesn't do anything.
I couldn't find what I am doing wrong, thus it's not working. What am I missing?
Here a fews of articles about Unwind, that was super for me, maybe that can help
Unwind

Resources