问题
This is a follow up to my previous question. I am trying to see if an email has already been used.
I am using the line
if snapshot.hasChild(email) {
I have in my database an email test1@test.com When I type that in..the moment I get to the '.' before com the app crashes and gives an error that says this
Must be a non-empty string and not contain '.' '#' '$' '[' or ']'
I see a lot of posts about checking for usernames, but my app doesn't have usernames, just email. Am I able to use email with
hasChild(...) {...
回答1:
Firebase keys cannot contain a .
(dot) character. If you want to store an email address in a key, you'll have to encode it. The common way to do that is to replace the .
with a ,
(comma), which conveniently is not allowed in email addresses. So test1@test.com
would be encoded as test1@test,com
.
I don't think you're actually storing the email address as a key, but I'll follow up for that on your previous question.
来源:https://stackoverflow.com/questions/41372563/swift-firebase-must-be-a-non-empty-string-and-not-contain-or