简体   繁体   English

是否可以在parse.com中注册新用户?

[英]Is it possible to signup new user in parse.com?

I am trying to signup a new user manually on parse.com from IOS code . 我试图通过IOS代码在parse.com上手动注册新用户。 I need this because i want to add 3-4 extra fields on signup. 我需要这个,因为我想在注册时添加3-4个额外的字段。 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. 注意-此答案请勿在解析中使用标准PFUser类。

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) 如果您未使用实际的PFUser类,则Parse中的任何内容均无效(例如,电子邮件验证,密码重置,帐户处理,等等)

To add extra fields using PFUser is very simple: (1) create the user in the normal way. 使用PFUser添加额外的字段非常简单:(1)以常规方式创建用户。 (2) in a separate call , send up the other fields. (2) 在单独的呼叫中 ,发送其他字段。 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. 经过大量RnD,我发现这可以解决我的问题。 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 子类PFUser像这样

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. 这就是我们使用PFUser进行注册的方式。 You can always add extra fields to PFUser class. 您始终可以向PFUser类添加其他字段。 Subclassing provides you this feature. 子类化为您提供此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM