2013-08-24 88 views
0

我想只能有一個登錄屏幕。用戶每次登錄時都會輸入用戶名,電子郵件和密碼。我遇到了註冊,註銷,然後嘗試使用相同憑據登錄的問題,並且我剛收到一條錯誤消息,說用戶名已被佔用。如果他們給我正確的憑據,我怎麼才能登錄他們?一次登錄查看,註冊或登錄

PFUser *user = [PFUser user]; 
user.email = emailEntry; 
user.username = nickNameEntry; 
user.password = passwordEntry; 
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) 
{ 
    if (!error) 
    { 
     [MYAlertView showAlertWithTitle:@"Successful login" 
           message:@"success" 
         cancelButtonTitle:@"OK"]; 
    } 
    else 
    { 
     NSString *errorString = [[error userInfo] objectForKey:@"error"]; 
     [MyAlertView showAlertWithTitle:@"There was an error signing up." 
           message:errorString 
         cancelButtonTitle:@"OK"]; 
    } 
}]; 

回答

0

如果用戶需要註冊(第一次),你需要使用–signUpInBackgroundWithBlock:,因爲你在做什麼。

但是,如果他已經註冊,我想你應該使用+logInWithUsernameInBackground:password:block:

我從this page得到這些信息,但是我從來沒有使用過這個SDK。

更簡單的方法來做到這一點是:

  1. 有兩個按鈕,是推動不同的視圖控制器,一個用於註冊,另一個用於登錄
  2. 相同的形式,和兩個按鈕,一個其中調用方法調用–signUpInBackgroundWithBlock:,另一個調用+logInWithUsernameInBackground:password:block:

對於第二種解決方案,問題是如果您有相同的表單,則在註冊時不能要求特殊信息(姓名,出生日期等)。

編輯: 你可能想看看:

  1. PFSignUpViewControllerDelegate
  2. PFLoginViewControllerDelegate
  3. Parse API Documentation(其中我發現上面的兩個鏈接)。