當提交創建新用戶的請求時,如果用戶嘗試使用無效的電子郵件提交,則應用程序崩潰(I.E.沒有@符號)。有沒有辦法通過Firebase檢查電子郵件是否有效,或者我需要驗證應用程序端?使用Firebase驗證電子郵件適用於iOS
我在控制檯得到的錯誤是:
*終止應用程序由於未捕獲的異常 'InvalidEmail',理由是: 'jfkdsla; fjdk是無效的電子郵件地址'
NSString *url = [NSString stringWithFormat:@"https://myapp.firebaseio.com/users/%@", displayName.text];
Firebase *dataRef = [[Firebase alloc] initWithUrl:url];
[dataRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
NSLog(@"Ref %@", snapshot.value);
snapshotValue = snapshot.value;
}];
if (snapshotValue == NULL) {
AppDelegate *appDelegate= (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.authClient createUserWithEmail:email.text password:password.text andCompletionBlock:^(NSError* error, FAUser*user) {
if (error != nil) {
// Error
NSLog(@"ERROR CODE: %d",error.code);
NSLog(@"ERROR: %@",error);
if (error.code == -9999) {
email.textColor = [UIColor redColor];
}
} else {
NSLog(@"Created %@",user.userId);
Firebase *userRef = [[Firebase alloc] initWithUrl:[NSString stringWithFormat:@"https://myapp.firebaseio.com/users/%@",displayName.text]];
[[userRef childByAppendingPath:@"name"] setValue:fullName.text];
[[userRef childByAppendingPath:@"user_id"] setValue:user.userId];
Firebase *userCredentials = [[Firebase alloc] initWithUrl:[NSString stringWithFormat:@"https://myapp.firebaseio.com/users/%@/credentials",displayName.text]];
[[userCredentials childByAppendingPath:@"email"] setValue:email.text];
[[userCredentials childByAppendingPath:@"password"] setValue:password.text];
AppDelegate *appDelegate= (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.authClient loginWithEmail:email.text andPassword:password.text
withCompletionBlock:^(NSError* error, FAUser* user) {
if (error != nil) {
NSLog(@"There was an error logging in to this account: %@",error);
} else {
NSLog(@"logged in");
[self dismissViewControllerAnimated:NO completion:nil];
[appDelegate.window.rootViewController presentViewController:appDelegate.tabBarController animated:YES completion:nil];
}
}];
}
}];
}
else {
displayName.textColor = [UIColor redColor];
}
}
有任何C ode或代碼片斷,表明您使用Firebase的*結果*進行操作?你還可以顯示提取電子郵件地址文本字段文本的代碼嗎? – 2013-04-03 22:07:31
這是我創建一個新用戶的代碼。 – 2013-04-03 22:11:58