Comments (138)

  1. Herolee

    Hello Dipin,
    I can not login on our site wordpress also PHP.
    Please help,
    Thanks,

  2. Hi,
    can you specify what u mean by “use our own data base instead of using local storage(USER DEFAULTS)”?
    Are you try to save the data in a local DB within the app instead of user defaults?

  3. Hi Rob,

    I am creating a tutorial for Login/Signup + auto login using touch id.
    But, it on Xcode 8 + objective C.
    I will try to add swift code too.

    Thanks.

  4. Rob Dingwall

    Hi Dipin,
    Many thanks for this excellent tutorial.
    Is it possible to update it for Xcode version 7.3.1?

  5. Alam Usmani

    Thanks a lot your post help me very much, i am recently switch to iOS from dot net.

  6. Luis

    Hi Dipin! I have the same problem that James, my xcode version is 7 beta.
    Nice tutorial
    Thanks.

  7. Check if the value exist:

    var email:NSString
    if((jsonData["email"]) != nil) {
        email = jsonData["email"] as! NSString
    }
  8. Christian

    i got an error when i tried to log in
    fatal error: unexpectedly found nil while unwrapping an Optional value
    xcode show green line at: var lastname:NSString = jsonData[“email”] as! NSString

  9. You need to pass the info you need in the JSON reply during login.
    Then parse the json and save it in the NSUserDefaults.

    Eg:

    var firstname:NSString = jsonData["firstname"] as NSString
    var lastname:NSString = jsonData["lastname"] as NSString
    var prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults()
    prefs.setObject(username, forKey: "USERNAME")
    prefs.setObject(firstname, forKey: "FNAME")
    prefs.setObject(lastname, forKey: "LNAME")
    prefs.setInteger(1, forKey: "ISLOGGEDIN")
    prefs.synchronize()

    Hope it helps!

  10. Christian

    Helo!
    I have one more column named email, how can i show user’s email when user login? And how to store all user’s information to NSUserDefaults with email, firstname, lastname, age…

  11. James

    I keep getting this error: fatal error: “unexpectedly found nil while unwrapping an Optional value”

    It is on this line of the code:

    “let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as! NSDictionary”

  12. Hey there,

    For whatever reason, no matter what I do whenever I create an account (with what I’m sure are unique usernames), it always says “username exists”.

    2015-08-05 14:01:52.746 PING[53354:2853979] Response code: 200
    2015-08-05 14:01:52.746 PING[53354:2853979] Response ==> {“success”:0,”error_message”:”Username Exist.”}
    2015-08-05 14:01:52.756 PING[53354:2853979] Success: 0

    I’m using Xcode 6 with iOS 8

    Any suggestions?

  13. Raghu

    Hi Dipin,

    I always get connection error when trying to connect to localhost php. I am using Xcode 7 beta.

    Let me know if any settings I need to apply to make it work ?

    Regards,
    Raghu

  14. Hi,

    The php script is not perfect.
    The error “username already exists” can be due to some other mysql related error.

    Thanks.

  15. Hi, I am wondering how to link the PHP file to the actual app, mine says error: username already exists even though it is completely random! Any help!

  16. Glauber Felix

    I got a lot of errors, I am at XCODE 7 beta,

    Could you fix it ?

    Thanks!

  17. Hey Keyur,

    1. Run the sql file.
    2. Create a new user/pass for the DB or you can use the root user.
    3. Update the DB host, username and password in the php files.
    4. Update the url in the swift code.

    That should do.

    Thanks.

  18. Keyur

    Thanks for the tutorial… one thing– I want to go ahead and make my own MySQL database to implement this system myself–still on a developmental standpoint.

    What all do I need to do (new to databases)?

    Do I need to change anything in the .php files you attached?
    In the code, do I just need to change the URL’s which link to your website and to mine?

    Thanks

  19. Karl Jennings

    This is great stuff. Didn’t use the entire code base but used it to find a problem in my own. I’m new to Swift, it really helped me out!

  20. Nadhif Fadhila

    hi im trying to use your db in my web and i get this error

    2015-07-06 18:00:20.324 SwiftLoginScreen[880:32379] PostData: username=qwe&password=qwe&c_password=qwe
    2015-07-06 18:00:21.813 SwiftLoginScreen[880:32379] Response code: 200
    2015-07-06 18:00:21.813 SwiftLoginScreen[880:32379] Response ==>
    Warning: mysqli::mysqli(): (28000/1045): Access denied for user ‘DB_USER’@’10.2.1.48’ (using password: YES) in /home/u342872465/public_html/jsonsignup.php on line 21
    {“success”:0,”error_message”:”Access denied for user ‘DB_USER’@’10.2.1.48’ (using password: YES)”}
    fatal error: unexpectedly found nil while unwrapping an Optional value
    (lldb)

    what happen with this? please help me

  21. Hi,

    The username might already exist of the DB.
    Or it can be some other error, you can better the php script to catch them.

    Thanks.

  22. Hello, I downloaded the source code and ran it from simulator and my iPhone and when I tap on the sing up button and sign up it brings up a popup menu saying Username Exist, why?

    Thank you,

    Rogelio

  23. hi, your tutorial is amazing it helps me a lot.
    i am new in xcode and swift and wanted to have more tutorial.
    i want to know how can we make feed like facebook ios app.
    also after login success i wanted to redirect to new viewcontroller so how will i achieve it.please guide.

  24. John Beany

    Thank you so much for fixing the errors in the latest version. It helped me out sooooooooo much! Thank you again!

Leave a comment

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.