这是我第一次使用Parse,在阅读了大量文档后,我开始使用它进行编码。
一切顺利,但我现在有一点问题/怀疑。我在某处读到,当现有用户尝试通过SignUpAsync调用再次注册时,SygnUpAsync应该抛出异常。对我来说,这不会发生,也不会抛出任何异常。在以前的版本中,这个方法似乎被命名为SignUpInBackground并且应用了相同的规则。
这是我在Xamarin.Android上使用的代码:
EditText passwordEditText = FindViewById<EditText>(Resource.Id.etPassword);
EditText userEditText = FindViewById<EditText>(Resource.Id.etUserName);
EditText emailEditText = FindViewById<EditText>(Resource.Id.etUserEmail);
string password = passwordEditText.Text;
string userName = userEditText.Text;
string email = emailEditText.Text;
if (!String.IsNullOrEmpty(password) && !String.IsNullOrEmpty(userName) && !String.IsNullOrEmpty(email))
{
try
{
ParseUser user = new ParseUser()
{
Username = userName,
Password = password,
Email= email
};
await user.SignUpAsync();
System.Console.WriteLine("User " + ParseUser.CurrentUser.Username + " has been registered.");
}
catch (ParseException ex)
{
//This is never called
_ShowAlertDialog("The given user was registed previously. " + ex.Message);
}
catch (Exception ex)
{
//This is never called
_ShowAlertDialog("Error: " + ex.Message);
}
}
else
_ShowAlertDialog("Some fields contain invalid values. Please, fix them and retry.");
}
有人可以澄清这个吗?
干杯。