I do not get any errors and the application builds fine but when I check parse, there is no new user added. here is the code:
import UIKit
import Parse
class ViewController: UIViewController {
@IBOutlet var passwordTextField: UITextField!
@IBOutlet var emailTextField: UITextField!
//@IBOutlet var messageLabel: UILabel!
@IBAction func loginVerifyButton(sender: AnyObject) {
var pwdEntered = passwordTextField.text
var emlEntered = emailTextField.text
if pwdEntered != "" && emlEntered != "" {
// If not empty then yay, do something
func userSignUp() {
var user = PFUser()
user.email = emlEntered
user.password = pwdEntered
user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as? NSString
// Show the errorString somewhere and let the user try again.
} else {
// Hooray! Let them use the app now.
}
}
}
}else {
//self.messageLabel.text = "All Fields Required"
}
You should be setting the userName of the PFUser as well, you are only setting the email and passwrod, but you should do this, ObjC, sorry:
PFUser *user = [PFUser user];
user.password = [[[self contentView] passwordField] text];
user.email = [[[self contentView] emailField] text];
user.username = [[[self contentView] emailField] text];
and then doing this:
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
//do work
} else {
//bad stuff
}
}];
Just set the userName to the the email address AND if you read the header files for Parse API, you find this:
@abstract Signs up the user *asynchronously*.
@discussion This will also enforce that the username isn't already taken.
@warning Make sure that password and username are set before calling this method.
@param block The block to execute.
It should have the following argument signature: `^(BOOL succeeded, NSError *error)`.
*/
- (void)signUpInBackgroundWithBlock:(PF_NULLABLE PFBooleanResultBlock)block;
This means that you must have a userName declared in the PFUser. So, change from this:
var user = PFUser()
user.email = emlEntered
user.password = pwdEntered
user.signUpInBackgroundWithBlock {
to this:
func myMethod() {
var user = PFUser()
user.username = "myUsername"
user.password = "myPassword"
user.email = "email@example.com"
// other fields can be set just like with PFObject
user["phone"] = "415-392-0202"
user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as? NSString
// Show the errorString somewhere and let the user try again.
} else {
// Hooray! Let them use the app now.
}
}
}
from Parse's web site itself
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.