Firebase Authを使用して新規ユーザー登録の機能を作っています。
画面下のコードのsignUpButtonを押しても、
self.performSegue(withIdentifier: "signUpToTabbarVCs", sender: nil)
が呼ばれません。
以下が各所にprint(a-f)を置き、呼ばれているか確認した結果です。
onSuccess: { 以下が呼ばれていませんでした。
コンソールで確認したところ、ユーザーデータは送信できていました。
以下の書き方で何が原因になっているのでしょうか?
ご存知の方がいましたらよろしくお願いします。
問題の部分
swift
1@IBAction func signUpButton(_ sender: Any) { 2 print("a") 3 if let profileImage = self.selectedImage, let imageData = UIImageJPEGRepresentation(profileImage, 0.1) { 4 print("b") 5 AuthService.signUp(username: nameTextField.text!, email: emailTextField.text!, password: passwordTextField.text!, imageData: imageData, onSuccess: { 6 print("e") 7 self.performSegue(withIdentifier: "signUpToTabbarVCs", sender: nil) 8 print("f") 9 }, onError: { (errorString) in 10 print(errorString!) 11 }) 12 } 13 14 } 15
firebase周りをまとめたもの
swift
1import Foundation 2import FirebaseAuth 3import FirebaseStorage 4import FirebaseDatabase 5 6class AuthService { 7 8 static func signIn(email: String, password: String, onSuccess: @escaping () -> Void, onError: @escaping (_ errorMessage: String?) -> Void) { 9 Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in 10 if error != nil { 11 onError(error?.localizedDescription) 12 return 13 } 14 onSuccess() 15 }) 16 } 17 18 static func signUp(username: String, email: String, password: String, imageData: Data, onSuccess: @escaping () -> Void, onError: @escaping (_ errorMessage: String?) -> Void) { 19 Auth.auth().createUser(withEmail: email, password: password, completion: { (user: User?, error: Error?) in 20 if error != nil { 21 onError(error?.localizedDescription) 22 return 23 } 24 let uid = user?.uid 25 print("c") 26 //Storage 27 let storageRef = Storage.storage().reference().child("profileimage").child(uid!) 28 storageRef.putData(imageData, metadata: nil, completion: { (metaData, error) in 29 if error != nil { 30 return 31 } 32 let profileImageUrl = metaData?.downloadURL()?.absoluteString 33 self.setUserInfomation(profileimageurl: profileImageUrl!, username: username, email: email, uid: uid!, onSuccess: onSuccess) 34 print("d") 35 }) 36 }) 37 } 38 39 static func setUserInfomation(profileimageurl: String, username: String, email: String, uid: String, onSuccess: @escaping () -> Void) { 40 41 //RDB 42 let ref = Database.database().reference() 43 let usersRef = ref.child("users") 44 let newUserRef = usersRef.child(uid) 45 newUserRef.setValue(["username": username, 46 "email": email, 47 "profileimageurl": profileimageurl]) 48 } 49 50} 51
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/17 08:59