Skip to content

the-nerd

iOS & web programming stuff.

  • About
  • Blog
  • Contact me

♥︎ social?

  • View bethenerd’s profile on Facebook
  • View thenerd_be’s profile on Twitter
  • View frederik-jacques’s profile on GitHub

♥︎ me?

♥︎ me?

Recent Posts

  • Announcing Clockwise App
  • Streamlining lots of View Controller interactions with Swift enums.
  • Swift Snippet : Map Bool values with Generics in Swift
  • TNInfoBubble – Prisma app info bubble component
  • Sketch app Favicon Exporter template

Recent Comments

  • Lucas Sebastian on CakePHP file upload validation
  • Lilanka on Add Unity3D in a native iOS application
  • Mr.Zeee on 3D touch peek and pop tutorial for your Swift application
  • Integrate Unity into a native iOS app – program faq on Integrate Unity 5 in a native iOS app with Xcode 7
  • alessio crestani on Integrate Unity 5 in a native iOS app with Xcode 7

Archives

  • April 2020
  • October 2017
  • September 2017
  • August 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • April 2014
  • October 2013
  • August 2013
  • June 2013
  • April 2013
  • March 2013
  • January 2013
  • August 2012
  • July 2012
  • February 2012
  • October 2011
  • September 2011

Categories

  • 3D Touch
  • ABC app
  • Android
  • AutoLayout
  • Boring Meeting OXO
  • CakePHP
  • Clockwise
  • Core Data
  • El Capitan 10.11
  • Experimental
  • Frameworks
  • GitHub
  • iCapital app
  • iOS
  • Local Authentication
  • Mapbox
  • Objective-C
  • Open Source
  • Opinion
  • OSX
  • OSX apps
  • SceneKit
  • Sketch
  • SpriteKit
  • Swift
  • Swift 2
  • Tilemill
  • TNCheckBoxGroup
  • TNColorScrollViewController
  • TNInfoBubble
  • TNRadioButtonGroup
  • TNSexyImageUploadProgress
  • TNSwiftyCheckboxGroup
  • TouchID
  • Tutorials
  • Uncategorized
  • Unity3D
  • Xcode
  • Yosemite 10.10

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Objective-C Login System Tutorial

For a few private projects the last couple of months I needed to implement a login system before the user could see the actual content.

It seemed like there were quite a few patterns people were using on how to implement such a system. The easiest way to go (imho :-)) is by creating a UIViewController which will serve the protected content and add it as the root view controller of your project. In that UIViewController you can then add a modal view controller which will present the login view.In the delegate message ‘viewDidAppear:’ you can then check if the user is already authenticated (e.g. from a previous session). In this example I check the state from a key in my NSUserDefaults dictionary, but you can implement your own authentication logic here. If the check returns a false answer, you can show the LoginViewController modally. Don’t forget to set the animated property to NO, so the user won’t see the content of your protected view controller for a second while the animation is running.

The reason why I do the check in viewDidAppear is because of the fact that only from this point you can show other (modal) view controllers. Before that point the view has not been added to the view hierarchy and you will get errors if you try to add something to it!

When the user has been authenticated, you just call dismissViewController: on the presentingViewController property and the login view controller will go away.  The default transition is a slide down, but you can change it by adjusting the modalTransitionStyle property before executing the dismiss!

Alright enough chitchat … just go check out the code on GitHub and see for yourself. If you have any remarks, feel free to reply!

Share this:

  • Facebook
  • Twitter
  • LinkedIn
  • Pocket
  • Reddit
  • Email

Like this:

Like Loading...
Posted on March 14, 2013Author frederik-jacquesCategories Objective-C, TutorialsTags login, modal, objc, objectice-c, system, tutorial

Post navigation

Previous Previous post: Enumerate fonts on your iOS device
Next Next post: Grading in the future?
© 2007-2022 the-nerd.be
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this: