I am trying to signup a new user manually on parse.com from IOS code . I need this because i want to add 3-4 extra fields on signup. Here is the code i am trying, but it is not inserting the data into user class :
PFObject *testObject = [PFObject objectWithClassName:@"User"];
[testObject setObject:@"bar" forKey:@"username"];
[testObject setObject:@"bar" forKey:@"password"];
[testObject setObject:@"1111111" forKey:@"additional"];
[testObject setObject:@"bar@123.com" forKey:@"email"];
[testObject setObject:@"2323233" forKey:@"phoneNumber"];
[testObject setObject:@"12,california" forKey:@"address"];
[testObject save];
Any help please. What i am doing wrong here?
NOTE - THIS ANSWER DOES NOT USE THE STANDARD PFUser CLASS IN PARSE.
Essentially it does not work. If you're not using the actual PFUser class, nothing in Parse works (example, email verification, password reset, account handling, blah blah)
To add extra fields using PFUser is very simple: (1) create the user in the normal way. (2) in a separate call , send up the other fields. Very often you will also have an image (like a user avatar) - send that up separately in another cal.
After a lot of RnD i found this as a solution to my question. I am sharing it here so that it would be useful to others also
-(void)userSignUp:(NSDictionary*)userData {
//username,password,additional,email,profilePic
ADUser *user = [[ADUser alloc] init];
user.username = [userData valueForKey:@"username"];
user.password = [userData valueForKey:@"password"];
user.email = [userData valueForKey:@"email"];
user.phone = [userData valueForKey:@"phone"];
user.additional = [userData valueForKey:@"name"];
PFUser *usr = (PFUser*)user;
[usr signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (error) // Something went wrong
{
// Display an alert view to show the error message
UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:[[error userInfo] objectForKey:@"error"]
message:nil
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[alertView show];
// Bring the keyboard back up, user will probably need to change something
//[usernameField becomeFirstResponder];
} else {
NSLog(@"success");
[self dismissViewControllerAnimated:YES completion:nil];
}
}];
}
I believe you need
PFUser *user = [PFUser user];
user.username = @"my name";
user.password = @"my pass";
user.email = @"email@example.com";
// other fields can be set just like with PFObject
-Bob
Subclass PFUser Like this
User.h
#import <Parse/Parse.h>
@interface User : PFUser <PFSubclassing>
@property (nonatomic, strong) NSString *nickName;
@property (nonatomic, strong) NSString *username;
@property (nonatomic, strong) NSString *email;
@property (nonatomic, strong) NSString *type;
@property (nonatomic, strong) PFFile* image;
@end
User.m
#import "User.h"
@implementation User
@dynamic nickName, email, type;
+(void)load {
[self registerSubclass];
}
+ (NSString *)parseClassName {
return @"_User";
}
@end
Then use following code to signup:
User *user = [PFUser user];
user.nickName = @"Alpha";
user.username=username;
user.password=@"0000";
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!error)
{
NSLog(@"Signup Success");
}
else{
NSLog(@"Signup Error : %@ ", error);
}
}];
That's how we use PFUser to signup. You can always add extra fields to PFUser class. Subclassing provides you this feature.
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.