iOS Login Form Controller
Fullstack Social iOS NodeJS REST
With the custom login now working for the browser, let's go ahead and create our iOS application that also allows us to login. Make sure that you have a good view of your server console as you are performing your network operations. In these iOS lessons, I'll be glossing over the UI portions since its quite tedious typing out the code. The interesting portions deal with networking where I'll be integrating the Alamofire framework to make our lives easier. Enjoy.

Comments (29)
shariar
4 years ago
Hi Brain! I tried to install LBTATools but i got this error [!] Unable to find a specification for `LBTATools`
Brian Voong
4 years ago
Tom Andrew
4 years ago
How Brian, How do you get the indent from the top, that is showing a snippet of the view behind it? Really like the effect but it's not appearing for me.
Tom Andrew
4 years ago
Oh, I didn't let the video finish. Haha all good.
Dustin Doosun Yang
4 years ago
error: SWIFT_VERSION '5.0' is unsupported, supported versions are: 3.0, 4.0, 4.2. (in target 'LBTATools') Even if I switched to 4.2 for swift languarge version, I keep getting an error
Dustin Doosun Yang
4 years ago
Never mind. I figured out I had to switch the swift version in framework level.(not entire project level)
ogarci10
4 years ago
How did you do this, I believe I am getting the same error. How would you switch swift versions at a framework level?
Brian Voong
4 years ago
ogarci10
4 years ago
I am using Xcode 10.3, now I get this error ' No such module 'LBTATools' '
ogarci10
4 years ago
nvm figure it out, just had to restart my Mac. Thanks tho!
Dustin Doosun Yang
4 years ago
When I hit the "Fetch Post" button I get following error App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 2019-08-02 00:29:44.834048-0400 SocialApp[57052:6024153] Cannot start load of Task <E6A99A59-E6F0-4907-8490-233D383AA9C8>.<1> since it does not conform to ATS policy I added "App Transport Security Settings" row and then added Allow Arbitrary Loads (YES). Still getting an error What should I do to resolve this?
Brian Voong
4 years ago
Dustin Doosun Yang
4 years ago
Thanks that works :)
Jeiel
4 years ago
hi Brian. In my code (HomeController line 48), I set UIWebView() instead WKWebView() because last one don't works well... error: "Use of unresolved identifier 'WKWebView'; did you mean 'UIWebView'?"
Jeiel
4 years ago
ok! i remove "import UIKit" and "import WebKit". so far so good... =)
Brian Voong
4 years ago
Jeiel
4 years ago
one more thing.. the "let formView" didn't work here.. I tried download ur project and it didn't work aswell.. so my views login and home views didn't scrolling as ur did. ??? =/
Brian Voong
4 years ago
Jeiel
4 years ago
I mean.. the login page don't drag down (or scroll down...). like formView didn't work (sorry about my English =p)
Brian Voong
4 years ago
Jeiel
4 years ago
Copy, its a great effect.. im not using iOS 13 / Xcode 11 but I will soon.. Thanks!
bmilts
4 years ago
Launching it programatically did not seem to work. I still had to embed in a navigation controller on the storyboard to see the fetch posts bar button item. Is this something new?
hariantara
3 years ago
Hi Brian, Do you have course for beginner for CRUD through REST API in Swift ? I want learn the basic and fundamental first before jump in this course Thank you
Brian Voong
3 years ago
ajeannoel
3 years ago
Hi Brian, some users still may encounter issues while allowing http://localhost:1337 to be reached from within their app. What I did is to allow "Allow local networking" setting to be YES (true) as you answered below. In addition, they'll have to check for their computer name (Go to Mac System Preferences -> Sharing). The computer name should look like <computer-name>.local They finally just need to replace http://localhost:1337 with http://<computer-name>.local:1337 and they'll be good to go.
Brian Voong
3 years ago
Majid Boudaoud
3 years ago
Hey Brian, I was wondering why using cookie storage and put such a long duration for it instead of using a refresh token using Auth0 or any other method ?
Brian Voong
3 years ago
Bobur Pakhriev
3 years ago
Hi Brian . i dont have an idea how to install pods. Can you help me out there?
noorajaa
3 years ago
- pod init - choose the cocoapod library - pod install
omari
3 years ago
Hi Brian, I am using Xcode Version 11.2 (11B52). I created the HomeController file and changed the code inside AppDelegate didFinishLaunching --> window?.rootViewController = UINavigationController(rootViewController: HomeController()). When launching the app I don't see the Homecontroller. I also tried to change the plist and added Main Storyboard file base name. Something is not working as usual. Please help
omari
3 years ago
My AppDelegate class also looks different: var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { window?.rootViewController = UINavigationController(rootViewController: HomeController()) return true } // MARK: UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. }
Brian Voong
3 years ago
omari
3 years ago
Thanks Brian for answering so fast. You really support us and it is not only about making money. Please keep it that way. Now I can see the Homecontroller when the app launches. I deleted and created the project many times. Wasted over an hour but did not find the issue ^_^
mdoor1123
3 years ago
Thanks, Brian. This video was really helpful.
jimmy hernandez
3 years ago
Hi Brian , Can you explain how do we can create transition like login and sign up controller , I really want to know How Codes work and create this nice feature .Thanks
omari
3 years ago
Q1: How do I start the server inside of the terminal to keep track of the HTTP Responses Q2: When I click fetchPost I see the following message inside of the console ------------------------------------------------------------------------------------------- Attempt to fetch post while unauthorized 2019-11-05 14:00:24.356821+0100 hylonet[17181:798089] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 2019-11-05 14:00:24.356955+0100 hylonet[17181:798089] Cannot start load of Task <6E8CD21B-7819-401C-8BA3-3CE2A243F999>.<1> since it does not conform to ATS policy 2019-11-05 14:00:24.410710+0100 hylonet[17181:798085] Task <6E8CD21B-7819-401C-8BA3-3CE2A243F999>.<1> finished with error [-1022] Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x6000013f5830 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://localhost:1337/post, NSErrorFailingURLKey=http://localhost:1337/post, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.} Failed to hit server: Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x6000013f5830 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://localhost:1337/post, NSErrorFailingURLKey=http://localhost:1337/post, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.} ------------------------------------------------------------------------------------------ Thats why I added following property into the list App Transport Security Settings > Allow Local Networking : YES When I restart the app I get the following error ------------------------------------------------------------------------------------------ Attempt to fetch post while unauthorized 2019-11-05 14:08:01.746572+0100 hylonet[17372:809381] [] nw_socket_handle_socket_event [C1.1:2] Socket SO_ERROR [61: Connection refused] 2019-11-05 14:08:01.748205+0100 hylonet[17372:809381] [] nw_socket_handle_socket_event [C1.2:2] Socket SO_ERROR [61: Connection refused] 2019-11-05 14:08:01.749220+0100 hylonet[17372:809381] Connection 1: received failure notification 2019-11-05 14:08:01.749403+0100 hylonet[17372:809381] Connection 1: failed to connect 1:61, reason -1 2019-11-05 14:08:01.749519+0100 hylonet[17372:809381] Connection 1: encountered error(1:61) 2019-11-05 14:08:01.755602+0100 hylonet[17372:809381] Task <55711CE6-C370-4D90-8361-9D54F033A32F>.<1> HTTP load failed, 0/0 bytes (error code: -1004 [1:61]) 2019-11-05 14:08:01.762740+0100 hylonet[17372:809378] Task <55711CE6-C370-4D90-8361-9D54F033A32F>.<1> finished with error [-1004] Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x6000019ba1f0 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=http://localhost:1337/post, NSErrorFailingURLKey=http://localhost:1337/post, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server.} Failed to hit server: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x6000019ba1f0 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=http://localhost:1337/post, NSErrorFailingURLKey=http://localhost:1337/post, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server.} ------------------------------------------------------------------------------------------ What can I do the fix this?
omari
3 years ago
I am searching since hours for this kind of error. I followed all your instructions. I am using Xcode Version 11.2 (11B52). There is not much online about it.
omari
3 years ago
Solved the issue ^_^ restarted the server.
Brian Voong
3 years ago
Bobur Pakhriev
3 years ago
Hey Brian, i installed all the pods, but i couldnt find a LBTATools pods ( instead im using LBTAComponents Is there a big difference?
Brian Voong
3 years ago
Bobur Pakhriev
3 years ago
Thanks will do that
Bobur Pakhriev
3 years ago
Hey Brian again, but i already installed pod "LBTAComponents" , how сan i update it?
Brian Voong
3 years ago
Bobur Pakhriev
3 years ago
Done!!! thank you )))
Bobur Pakhriev
3 years ago
hey Brian, i have finished the app and wanted to run on my iphone but its not showing up and i changed the Service.swift url to my ipadress but no result? did i miss something to change or did i made it wrong? thank you in advance
JaimeHe
3 years ago
Excuse me Brian,feel quite confused about this episode. Do I need to download your project firstly to complete this episode's coding part? But it seems that the linked project is already completed and it illustrate the error that the module "LBTATools" cannot be found or used. I am not quite familiar with the pod part and currently have no idea how to start with this episode's content. Or do I need to build the whole UI Component from scratch?
joeypozzyclinch
3 years ago
In case anyone comes across the same problem as me: the navigation bar wasn't showing up at all! So, first I followed how he handled showing the HomeController (by modifying the scene delegate) in the beginning of this video: https://youtu.be/1sn-io2OCtw But the navigation bar still wasn't showing up! So, I changed my "willConnectTo" section to as follows: var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) window.rootViewController = UINavigationController(rootViewController: HomeController()) self.window = window window.makeKeyAndVisible() } }
joeypozzyclinch
3 years ago
btw, the "willConnectTo" section is in the SceneDelegate Hope this helps!!
suliman
3 years ago
hey Brian, I follow this course but i use swiftUI now and i have problem after login (using native URLSession not library) it's work but after i open fetch post page it ask me again to login. i try to copy cookies using HTTPCookieStorage and put it into fetchpost() URLSession but not working so please help!
suliman
3 years ago
resolved :) I need to save cookies after login successfully after that fetchpost() work fine this my function for login: func sendLogin() { let url = URL(string: "http://localhost:1337/api/v1/entrance/login") guard let requestUrl = url else { fatalError() } let email = self.email let password = self.password // HTTP Request Parameters whick will be sent in HTTP Request Body let params = ["emailAddress": email, "password": password] let finalBody = try! JSONSerialization.data(withJSONObject: params) // Prepare URL Request Object var request = URLRequest(url: requestUrl) request.httpMethod = "PUT" // Set HTTP request body request.httpBody = finalBody request.setValue("application/json", forHTTPHeaderField: "Content-Type") let defaultSession = URLSession(configuration: .ephemeral) defaultSession.dataTask(with: request) { (data, response, error) in guard let data = data else { return } if let dataString = String(data: data, encoding: .utf8) { print("Response data string: \(dataString)") // self.showCookies() // set Cookies to HTTPCookieStorage that work Global let resp: HTTPURLResponse = (response as? HTTPURLResponse)! let cookies:[HTTPCookie] = HTTPCookie.cookies(withResponseHeaderFields: resp.allHeaderFields as! [String : String], for: resp.url!) HTTPCookieStorage.shared.setCookies(cookies, for: response?.url!, mainDocumentURL: nil) // dismiss View self.presentationMode.wrappedValue.dismiss() } }.resume() }
Danny S
3 years ago
Hi Brian, What is Pod? how can I install it?
Brian Voong
3 years ago
Danny S
3 years ago
hi Brian, thanks for your quick reply, yes, I found the information, but got error when I try to install it and don't know how to fix it. Is it possible to skip this step and build from scratch?
Danny S
3 years ago
hi Brian, xcode-select --install and sudo xcodebuild -license sudo xcode-select --switch /Library/Developer/CommandLineTools solve the issue.
Danny S
3 years ago
For those who like me, once you completed the cocoapods installation, you can now add pod to your xcode project. you can check the steps with https://medium.com/@soufianerafik/how-to-add-pods-to-an-xcode-project-2994aa2abbf1
bmilts
3 years ago
Hi Brian, Did I miss the part where you go over the login error checking? Is the code available? Thanks, Brendan
Udin Rajkarnikar
3 years ago
If you have Alamofire.request error and you use 'alamofire5' branch just change Alamofire.request to "AF.request"
georrgee
3 years ago
Appreciate that!
pris
3 years ago
Hi Brian, Regarding the setting/change I have to do at min 24:00, to make the app run on an iPhone device. I really didn't get it, I have my IP address but then what should I do with this info? So far I tried to change my iPhone's IP, to share my internet connexion from Mac to iPhone, nothing is working for me. Could you please, shortly explain the steps to make it works? Thank you for everything.
Brian Voong
3 years ago
pris
3 years ago
Thank you so much for your fast reply. Works like a charm. Have a wonderful day.
Setwork44
3 years ago
Every time you say the word "cookie" it makes me giggle uncontrollably and I don't know why. Especially when I read the syntax, "for each cookie in cookie!" (I want cookies now) ? Anyway the Login button is not working for me and I don't know why...
Setwork44
3 years ago
this is the error 'Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. '
caldwell 619
3 years ago
Copy and pasting might be easier for you, but that tedious UI code is the only reason I bought this course. There are a million and one tutorials on how to setup HTML / CSS, but very few that use code to create UI in Swift / iOS. Pretty bummed that you're just glossing over a huge aspect of creating this full-stack app.
Brian Voong
3 years ago
Nelson Pedrozo
3 years ago
Brian, I just want to thank you for taking user feedback so seriously (and quickly!). You are an outstanding teacher (the best online teacher I've ever seen, I might say) for many reasons, and this, right here, is one of them. I consider myself lucky to have found out about your courses and am always excited about the next lesson. Thanks, and keep up the excellent work!
Christopher J. Roura
2 years ago
I appreciate your response and do have an idea that might make things easier for you and for the development of any apps. Being that a lot of this code is tedious setup code it might be a nice idea to have optional videos, possibly even just older videos of yours, that cover the topic at hand (ex. the my journal tutorial on YouTube for the sails section). These older videos or optional videos would than be placed in as gap fillers to avoid the giant copy pasting in the projects. In addition these optional videos could be seen as homework for those that are invested in the course. So while you may not cover the entirety of the app in every video the students of your course will be able to feel like they aren't so far behind when purchasing a new course. This way if they purchased a course without seeing any previous content they won't feel like they've been skipped over.
gerkov77
3 years ago
In case someone ran into the same issue; Alamofire.request(...) is now only working as AF.request(...).
gerkov77
3 years ago
Oh someone was faster, I see, but I can't delete this now.. I should have read the comments first.
Lazaro Ambrosio
2 years ago
Thanks for the heads up!
gerkov77
3 years ago
Hi Brian, in session.js setting cookie: { _expires: 356 * 24 * 60 * 60 * 1000 } did not result in cookies with expiration time of one year. They are still just around 8 hours. I am not sure why. I also checked the Sails documentation, where they recommended using this form : session: { cookie: { maxAge: 365 * 24 * 60 * 60 * 1000 } } but this also did not change the cookie expiration date in the ios app's Xcode console. (Yes I have hit save, and server restarted). Any ideas in this? Thanks, Greg
Nick He
2 years ago
Hi Brian, I just started following the course. I got an error when I hit the Fetch posts button. Both in my own project and the project I downloaded here. The error is: "Failed to hit server: Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLStringKey=http://localhost:1337/post, NSErrorFailingURLKey=http://localhost:1337/post, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <39F1563F-7896-4B56-A1B0-DA7BB4285F69>.<1>" ), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <39F1563F-7896-4B56-A1B0-DA7BB4285F69>.<1>, NSUnderlyingError=0x6000026713b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}}" Not sure what that problem is. Looking forward to hearing from you. Cheers, Nick
Nick He
2 years ago
Problem solved.
Christopher J. Roura
2 years ago
Hi Brian, I am getting this error and i am not sure where it is coming from. I am able to login but the second I login I get this error. If I login through the customauth/login route it brings me to my posts where i can post as my user but the second i go to account overview i get this error again. The error is this: account-notification-banner.component.js:55 Uncaught (in promise) CloudError: Endpoint (`observeMySession`) responded with an error (or the request failed). at Object.exec (http://localhost:1337/dependencies/cloud.js:649:33) at http://localhost:1337/dependencies/cloud.js:612:26 at new Promise (<anonymous>) at Object.toPromise (http://localhost:1337/dependencies/cloud.js:610:24) at Object.then (http://localhost:1337/dependencies/cloud.js:592:36) Error Summary: (see `.responseInfo` for more details) ·-------------·----------------------------------------· | Protocol | ws(s):// (io.socket) | Address | POST http://localhost:1337/api/v1/observe-my-session | Exit | error | Status Code | 404 ·-------------·----------------------------------------· Response Body: Not Found
HELP & SUPPORT