2016-05-24 31 views
3

firebaseユーザログインの読み込み可能なuserfrendlyエラーメッセージを印刷しようとすると、NSError.localizedDiscreptionを使用できないことがわかりました。Firebase認証ログインのNSErrorからエラーメッセージを取得する方法

と私は非常に読みやすいではありませんが、私は、エントリー1、コード0、コンテンツ「INVALID EMAIL」

とのメッセージがあるで見つけ print(error)コマンド

2016-05-23 21:29:33.035 Mission Board[3251:] <FIRAnalytics/INFO> Firebase Analytics enabled 

Optional(Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={NSUnderlyingError=0x1277e2bb0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey=<CFBasicHash 0x1288eec60 [0x1a172a150]>{type = immutable dict, count = 3, 

entries => 

    0 : <CFString 0x12890ad60 [0x1a172a150]>{contents = "message"} = <CFString 0x1288eec20 [0x1a172a150]>{contents = "INVALID_EMAIL"} 

    1 : errors = <CFArray 0x12890ad20 [0x1a172a150]>{type = immutable, count = 1, values = (

    0 : <CFBasicHash 0x12890c660 [0x1a172a150]>{type = immutable dict, count = 3, 

entries => 

    0 : reason = invalid 

    1 : message = <CFString 0x128872790 [0x1a172a150]>{contents = "INVALID_EMAIL"} 

    2 : domain = global 

} 



)} 

    2 : code = <CFNumber 0xb000000000001903 [0x1a172a150]>{value = +400, type = kCFNumberSInt64Type} 

} 

}}, error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.}) 

を使用するときに、私のエラーメッセージは、次のようになります

アラートにその部分だけを出力することはできますか?

そこにはどのような機能が組み込まれていますか?

+0

私はあなたがエラーを脅かす必要があると思います。ユーザーはこれを理解できません。パスワードの脆弱性のような異なるエラーを試みると、電子メールが既に存在している場合、エラーは同じ形式で表示されます。メッセージフィールドにエラーの正しい原因がありますが、コード内にあります。すべての原因を何らかのエラーにやさしいメッセージ、またはそのほとんどに翻訳できます。 – ByteArtisan

+0

どうすれば変更できますか?私はそれが文字列の権利ではないという意味ですか? –

+0

可能なメッセージの内容ごとにいくつかのスイッチを追加することを意味します。 この場合、「INVALID_EMAIL」は「無効なメールが入力されました」と解釈する必要があります。 – ByteArtisan

答えて

0

以下のコードは、私のサインアップエラーコントロールです。私は警告のためにKVNProgressポッドを使用します。

Swift3

import KVNProgress 

FIRAuth.auth()?.createUser(withEmail: self.emailTextLbl.text!, password: self.passwordTextLbl.text!, completion: { (user, error) in 

if error != nil { 

    let error2:NSError = error as! NSError 

    if error2.code == FIRAuthErrorCode.errorCodeInvalidEmail.rawValue { 

     KVNProgress.showError(withStatus: "Invalid Email", completion: nil) 

    }else if error2.code == FIRAuthErrorCode.errorCodeNetworkError.rawValue { 

    KVNProgress.showError(withStatus: "Network Error", completion: nil) 

    }else if error2.code == FIRAuthErrorCode.errorCodeWeakPassword.rawValue { 

    KVNProgress.showError(withStatus: "Weak Password", completion: nil) 

    }else if error2.code == FIRAuthErrorCode.errorCodeEmailAlreadyInUse.rawValue { 

    KVNProgress.showError(withStatus: "Email Already In Use", completion: nil) 

    } 


}else{ 


    // Your code 


} 

}) 

あなたは、このようなログインエラー処理として "FIRAuthErrorCode" で他のエラーコントロールを見つけることができます。

関連する問題