How do I use Firebase Authentication using multiple view controllers? - swift

I am in the process of adding the Create new user Method for Firebase. I have already completed the SignUp Auth process. However when users are creating a new account. How do I go about this if I have multiple ViewControllers?
For example,
The First SignUpViewController - User is asked to enter their email address.
When the user clicks next. This is then followed by another ViewController.
SecondViewControlle - User is asked to enter their name and create a password.
After this, The user is greeted with a Welcome page with their name they submitted. (Welcome to “App Name” Name). Which will then proceed to the home UI after next is clicked.
How do I implement The Auth.auth().CreateUserwith func when I have more than one ViewController? Is there a way to save the email and password using two different ViewControllers?
Update**
I have added the following code that was suggested below, however the App crashes every time I click next on the enter your " Email" View Controller. I am getting this warning. Does anyone know what I did wrong? The rest of the code seems to be working fine. Here is a screenshot.

You can save all information in a Dictionary and use it at the time of SignUp. In your AppDelegate class:
/// Instance of AppDelegate
static let shared: AppDelegate = UIApplication.shared.delegate as! AppDelegate
/// Dictionary for user information
var userInformation: Dictionary<String, Any> = [:]
On Email Screen - Next Button Click
/// #1. Validate the email address
/// #2. Save it in Dictionary
AppDelegate.shared.userInformation["email"] = "xyz#gmail.com" or tFEmail.text.lowercased()
Then On name and password screen
AppDelegate.shared.userInformation["name"] = "xyz" or tFName.text
AppDelegate.shared.userInformation["password"] = "xxxxxxx" or tFPassword.text
Now on last screen - Sign Up Button clicked you can use all this information
let email = AppDelegate.shared.userInformation["email"]
let name = AppDelegate.shared.userInformation["name"]
let password = AppDelegate.shared.userInformation["password"]
Implement the Firebase SignUp method and after successfully logged in show the welcome screen.

Related

Swift Stripe Access DidCreateToken

I'm trying to integrate Stripe into my ios (Swift) app by using Firebase-Cloud-Functions. Now I'm want to get the token to a created card to save it into my Firestore-Database.
I've followed this tutorial on how to implement it. It's working when I'm displaying my addCardViewController on my own since I have the method didCreateToken. But now that I'm just showing it programmatically like shown in their provided example (row 158 is where they're showing the view controller) I don't know how to implement this method and get the token of the card if a user creates/adds a new one.
Thats what Id normally do:
func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: #escaping STPErrorBlock)
{
STRIPE_CUSTOMERS_REF.document(userId).collection("tokens").addDocument(data: ["token": tokenId]) // Calls Firebase-Cloud-Function and adds payment method to Stripe
navigationController?.popViewController(animated: true)
}
But like I said Im not able to implement this method.
I want to get the token when a user adds a new card.
Id really appreciates any kind of help. If you need any additional information let me know.
-Marie
It looks like you using STPPaymentContext (Standard Integration) to present the STPPaymentMethodsViewController (line 158 in the example above).
STPPaymentContext actually implements its own instances of STPPaymentMethodsViewController and STPAddCardViewController. Therefore, STPPaymentContext handles the delegate methods for those 2 view controllers and those aren't exposed to the user when using the Standard Integration. Which explains why that delegate method is not triggering for you.
Instead, your view controller should become the delegate for STPPaymentContext and implement the all the required delegate methods [0], including paymentContextDidChange method.
paymentContextDidChange method is triggered whenever a user adds a new card or selects a new payment method [1].
When a user enters new card details, you should be able to get the token ID with the following:
func paymentContextDidChange(_ paymentContext: STPPaymentContext)
{
if let card = paymentContext.selectedPaymentMethod as? STPCard {
let token = card.stripeID
// store token as required
}
}
Hope that helps!
[0] https://stripe.github.io/stripe-ios/docs/Protocols/STPPaymentContextDelegate.html
[1] https://stripe.github.io/stripe-ios/docs/Protocols/STPPaymentMethod.html

how to pass data from one view controller to another and between the view controller there is a reveal view controller [duplicate]

This question already has answers here:
Passing data between view controllers
(45 answers)
Closed 4 years ago.
Login to the page using email id and password and then i want to send data from login page to profile page, but my profile page is linked with the SWrevealviewcontroller as of to show side menu.
I am trying using default values.
Login View controller]2 form which i want to send data to profile view controller.
]4
Any suggestions what should i do?
Thank you!
You can make use of userDefaults, eg in LoginViewController save data to be used, as done below:
UserDefault.standard.setValue(name, forKey: "User_name")
UserDefault.standard.synchronize()
To use saved data on profile screen:
if let userName = UserDefault.standard.value(forKey: "User_name") as? String {
self.lblUserName.text = userName
}
Hope this helps out somehow.
One way to do this could just be using a global variable. A variable is made global if you put it above the class declaration. Example:
var globalInt = 7
class example....{
// blah blah blah, class code here
}
By doing this, if you change the variable in one screen, if another screen tries to access it after it has been modified, it will access the modified version. So for example if I were to change globalInt to 9 inside the class example, if I then accessed globalInt on another screen, it would be 9. Also, you can modify and access a global variable the same as if you were accessing any variable within the class.

Core Data detail view Error

I have been working on an app that has a tableview where users can add information on a seperate ViewController via UITextField. I am now trying to set it up so the user can tap on any given Cell to be able to view the data back on that ViewController or edit it again. Everything is being saved using CoreData.
Best way is you can put the check like this. So that it will never crash or throw the error:-
if let sender = sender as? String {
guest.player = sender
}

Why NSNotification work slow?

I know its interesting title for my question. Sorry for that. Here is my problem;
I am doing simple login screen (with facebook frameworks). If user wants to login with his/her facebook account, firstly he/she must confirm facebook page. And then i get their email addres, name, surname..etc information of user.
After that i just ask them password for my app. This password screen is a view. and opening on main view(not as new viewcontroller. its view on main view) And after confirm facebook page then this wiew appear.
On this password view has 2 textbox and 2 button. textbox for paswword(and confirmation) and First button send request to my web service with user information. and other button is "cancel" button.
here is the problem. When user send request i create nsnotification for waiting respond. after getting respond. i want to this password view get hide.
here is the code:
#IBAction func buttonSave(sender: AnyObject) {
var myObj = connectObject()
myObj.sendRequest("http://localhost:8888/iphone/hearMe/index.php", param: "id=test123")
NSNotificationCenter.defaultCenter().addObserver(self, selector: "actOnSpecialNotification", name: "sendDataCheck", object: nil)
}
func actOnSpecialNotification() {
println("ok I got success respond from webservice")
self.viewPassword.hidden = true /*This is my view */
}
with this code. "viewPassword" view hided but not instantly. It hide after 10 or 15 seconds. How i can hide that view instantly after getting response from webservice?
It's not clear from your question whether the 10-15 seconds is between the pushing of the button and the hiding of the view, or between the printing of "ok I got…" and the hiding of the view.
If the lag is between pushing the button and calling actOnSpecialNotification(), then the above code doesn't help us. We need to know what object posts the notification sendDataCheck and why it takes so long. Maybe it just takes that long to talk to the network. Maybe it posts the notification before you start observing it. You probably want to call addObserver() before sending the request rather than after (just in case there's an async operation in there).
If the lag is between printing the "ok I go…" line and hiding the view, then the most common cause of that is that the notification was posted on a background queue. You can't interact with UIKit anywhere but the main queue, and weird lags are a common symptom when you do.
(Side note: when in doubt, use let, not var. myObj is better defined let here. This helps protect against many kinds of bugs.)

Alert password field that stores password into the keychain and checks it against original login view controller

This is what I would like to happen I have screwed this up 60 times over now.
Ok, I have a login View Controller that handles the login using the username and password and a remember me switch. The login view controller verifies against an API, checks the credentials then proceeds. If the user has selected the remember me switch the password is stored. Next I have a separate deposit view controller. Once the user clicks the deposit button within this deposit controller it pops up an alert with a password field and once the password is entered it checks against the original login screen password to see if they match if they do. It pushes on another view controller and then life goes on. Otherwise if it doesnt match the stored pass and alert with and error is presented.
This just doesnt seem that hard but I'm having the hardest time with it I hope I made myself clear and questions let me know.
-Justin
In order to save text entered in a textField in an alertView, you have to store it in another variable before the alertView is dismissed. I use -(void)textFieldDidEndEditing:(UITextField *)textField to store the variable, since that is called after editing is complete, but before the alertView is dismissed.
Hope this helps!