First time launch/Has logged Storyboard View Controllers Swift - ios

I have a Page View Controller as an introduction tutorial off to the side. My Login/SignUp VC's segue to the Tab Bar Controller. Which is my home.
Here's what I am trying to accomplish:
If it's the users first time launching the app, go to the Page View Introduction which leads them to the Login/SignUp.
If the user has logged in before, then go to the home screen of the tab bar controller.
My Login/SignUp view controllers are the set to the initial view controllers. (I use Parse if that matters). I'm guessing I should set the Page View introduction tutorial as the initial view controller? I can link the Login/SignUp VC's to the Page View but don't really know where to go from there. All the answers I've found have been in Objective C, which doesn't help.. Thanks!

What you want is called NSUserDefaults, you can read about it here:
It works as a key-value mechanism that will store data in your app. When you finish launching the app (applicationDidFinishLaunchingWithOptions in app delegate) you can do something like this:
let defaults = NSUserDefaults.standardUserDefaults()
if defaults.objectForKey("userAsLoggedInBefore") {
//here you insert the code to go to the home screen
} else {
//this means the user hasn't logged in before and you can redirect him to the registeration page
}
To set the "User Logged In Information", you just have to put the following code when you want it to happen (in this case after the first sucessfull login)
NSUserDefaults.standardUserDefaults().setObject("1", forKey: "userAsLoggedInBefore")
If you need any more help, just say and I'll try to help you.

Related

SWrevealviewcontroller should be visible on welcome screen after login

I am new to iOS ran into a problem, I have successfully implemented SWRevealViewController side menu and it works if I put the view controller as initial screen but when it comes to showing it after login procedure it does not show up the menu, so after searching the web for quite some time I found out that I need to design a separate story board for login and register and separate for other screens.. so I did it as per that. Still, I have problems in showing up my side menu. My code does not get in
if revealViewController() != nil{ }
It returns NULL so the code does not go ahead.
And this is my second storyboard:
I am using UserDefaults to keep whether the user is logged in or not and storing user profile details in UserDefaults as well to be used within the app for future.
No need to use second storyboard.
You can simply switch between UIViewControllers by implementing a container view controller, if not using segues for specific reasons.
However, what I would suggest is to set your main view controller, revealViewController?, as an initial view controller, and check login status (using your UserDefaults) on viewDidLoad(). If there's no available login info, modally present another view controller for the login process. Then simply dismiss the login view controller if login succeeded.

Returning to login page after registration is done

How do you return to a previous page after it has been left. For example my app opens to the loggin screen, you can login or register when you register it takes you through a multipage and multi view controller process. When the registration finishes I want them to be taken back to the starting loggin page.
Can anyone help me on how to do that?
You want to use either dismissViewControllerAnimated, which you would use for example if the View Controller was presented modally. You might also want to try popViewControllerAnimated if you are using Navigation Controller.
I'd recommend reading the UIViewController Class Ref or the UINavigation Controller Class Ref.
If you are using a navigation controller (which would be highly recommended in a multi-VC process) the best solution would be using Unwind Segues.
You can see Apple's Documentation on using them, but to briefly explain the process:
Create a method on your login page with the signature #IBAction unwindToLogin(segue: UIStoryboardSegue)
Create a segue in the View Controller you want to go back to the login screen from that leads to the view controller's exit icon. The exit icon is shown below
When creating the segue, select the unwindToLogin function and give it an identifier if you are planning to call it programmatically.
Treat it how you would any other segue, and it should work!

Conditionally Produce two different view controllers from single UITabBarItem

I'm writing an iOS application that includes a UITabBarController, where one of the tabs is the user's profile. However, if the user is not signed in, I would like the application to display a different ViewController (Sign in/Sign up) instead.
I currently have the profile tab routing to a navigaion controller which has its RootViewController as ProfileViewController. In ProfileViewController's viewDidLoad, I have a check to see if the user is signed in. If the user is not, It performs a segue to SignInSignUpViewController which eventually loops back to ProfileViewController.
This approach is over-complicated and broken in a couple ways. For example, the navigation controller allows for the user to back into the signup/signin view controller after they've already signed in.
I feel like this is a pretty common idiom in iOS, but I can't find a good solution online. Anyone have any ideas?
Thanks in advance!
You might want to take a look at the UINavigationController method – setViewControllers:animated:. After you've logged in call this and pass your profile ProfileViewController. It will then be at the top of the stack, so the user won't be able to navigate back to the login view controller.

How should login screen appear on start of application IOS

I am making a new application there i have 5 tabs in it, its a user based application so i have to get the credentials of users login and passwords .
I am using storyboards with Arc , since its a Tabbed application so my initial view controller is my tab view controller , I wish to add a login screen also (probably as Modal View or an).
I am not able to think the perfect way to add a login screen in the tabbed application .
Should i call it from app delegate or in view will appear or some of these methods . I tried some of the code but ended up with warning like unbalanced call etc.
Need your valuable suggestions :)
Thanks in advance !!!
Just two options (of course there are more):
Use one UIViewController as rootViewController in the beginning of your App. Once the login is successful it will switch the window's rootViewController.
Put the UITabBarController as rootViewController, on viewWillAppear, check if the login has been made, if not, just show the Login's UIViewController

How to remove UINavigationController first view in stack after used?

I have a UINavigationController which has a loginview that appears once the app has loaded.
Once the user clicks Login, we push the next view onto the stack and it appears. I want the user to not be able to go back to the loginview.
How do I remove the loginview from the stack after the next view is loaded?
Note: It is a requirement that the only container of the app is a UINavigationController.
You can use setViewControllers:animated: to modify the controller stack, but I'd encourage you to reconsider whether you really want your login view controller to be the root of your navigation stack. When users see a navigation controller, they expect to be navigating up and down a hierarchy of screens organized in a tree structure. Changing the root of that tree undermines the metaphor somewhat.
Consider using modal presentation to communicate the the fact that the login experience falls outside of your app's main hierarchical navigation structure. Here are a couple options:
A. Start on login view controller, and present the navigation controller modally.
If your login view controller is always going to be the first screen the user sees, you could add its view directly to the window without the navigation controller. Then once the user logs in, create the navigation controller and present it by calling presentModalViewController:animated: from your login view controller.
B. Initialize the navigation controller with its true root, and present the login view controller modally.
This option may be worth considering if the login prompt isn't always the first view the user sees, especially if the login prompt can pop up in other contexts. For example, I used this approach in an app that allows the user to access some sections while offline or anonymous. The login prompt gets presented modally when the user tries to access content requiring authentication.
Remove the back button, by setting the backButtonItem, on the navigationItem of the login controller, to nil.
In above case your loginview Controller will be called root controller for your UINavigationController
Read below How to remove Root controller of UINavigationController
http://starterstep.wordpress.com/2009/03/05/changing-a-uinavigationcontroller%E2%80%99s-root-view-controller/
I found that by just setting the ViewControllers property, that would do the trick.
(We use C# and .NET to build iPhone apps with MonoTouch)
public override void ViewDidAppear (bool animated)
{
NavigationController.ViewControllers = new UIViewController[] { this };
}
use NSUserdefault to set bool check value to verify to show login page or next page
for example while login page u will get username password then send it to server and u will recieve the result as success or fail
if success then set the Bool in NSuserdefault to yes
and push nextview after successfully login.
if next time user come to ur app u have to first check out NSuserdefault for that bool value
according to that u can push nextviewcontroller or login page.
that's it.
in nsuserdefault u can specify string for key instead of bool
after succesfull login
set isLogined to yes
NSUserDefaults *std = [NSUserDefaults standardUserDefaults];
[std setObject:#"yes" forKey:#"isLogined"];
if not set NO
in before push login page just verify if the isLogined yes or no
according to that u can push login page or nextpage
to verify
[std stringforkey:#"isLogined"];

Resources