在我的应用中,当我首次加入用户时,我登录了他们,并确认此方法有效并且他们获得了用户ID。但是稍后在我的情节提要中,我调用Auth.auth.currentUser.uid,结果为nil。在我的代码中,我绝不注销用户。这个问题对我来说非常奇怪,因为在大多数视图控制器b4中,使我的应用崩溃的那个控制器,currentUser.uid都可以正常工作,并且我能够将用户的数据存储在Firebase上。我尝试调试并得出结论,关于此Viewcontroller代码的某些事情使此属性无效。有人遇到过这个问题b4吗?这是我的一些视图控制器代码。 *注意:对于变量DatabaseRef,我在类的顶部声明。我已经读过一些有关范围的概念的信息,可能是这里的问题?
func getArrayOfMatches(){
dataBaseRef=Database.database().reference()
usedArray.removeAll()
randomNumberArray.removeAll()
finalPeopleArray.removeAll()
peopleArray.removeAll()
print(Auth.auth().currentUser?.uid)
getUserGender()
getUsersMatchPreferences()
checkWhatPoolToDraw()
getArray()
}
func getUsersMatchPreferences(){
dataBaseRef=Database.database().reference()
dataBaseRef.child("Users").child(Auth.auth().currentUser!.uid).observeSingleEvent(of: .value) { (snapshot) in
if let dictionary=snapshot.value as? [String:AnyObject]{
self.userMatchPreferences=dictionary["AttractedTo"] as! String
}
}
}
func getArray(){
dataBaseRef=Database.database().reference()
dataBaseRef.child("Users").child(Auth.auth().currentUser!.uid).child("oldPotentialMatches").observeSingleEvent(of: .value) { (snapshot) in
let previousMatches=snapshot.value as? String
if let oldPotential=previousMatches{
self.usedArray.append(oldPotential)
}
}
dataBaseRef.child(poolToDraw1).observeSingleEvent(of: .value) { (snapshot) in
let personBook=snapshot.value as? String
if (personBook != nil) && !self.usedArray.contains(personBook!){
self.peopleArray.append(personBook!)
}
}
getRandomizedNumbers()
for i in 0...9{
let randomNumber=randomNumberArray[i]
let randomID=peopleArray[randomNumber]
finalPeopleArray.append(randomID)
usedArray.append(randomID)
}
for i in 0...usedArray.count-1{
dataBaseRef.child("Users").child("")
}
}
func getRandomizedNumbers(){
var numIterations = 10
if peopleArray.count < 10 {
numIterations = peopleArray.count
}
for i in 0...numIterations{
var randNumb = Int(arc4random_uniform(UInt32(peopleArray.count)))
while randomNumberArray.contains(randNumb){
randNumb=Int(arc4random_uniform(UInt32(peopleArray.count)))
}
randomNumberArray.append(randNumb)
}
}
答案 0 :(得分:0)
如果您是100%的用户,则登录到可以在屏幕上显示用户UID的位置,但是您无法执行其他任何操作,那么最可能的问题是数据库的Rulles,因此您需要转到在Firebase控制面板上,单击左侧菜单上的“数据库”,然后在蓝色菜单上单击“标尺”。仅用于测试,您可以这样做。
{
"rules": {
".read": true,
".write": true
}
}
答案 1 :(得分:0)
编辑您的config.xml以引用使用Firebase时需要为IOS进行此操作的GoogleService-Info.plist,一种工作方法是使用不需要此功能的Firebase Web API,但我不知道是否可以用Swift完成。
获取说明,可以将其放在文件夹中
https://firebase.google.com/docs/ios/setup
<platform name="ios">
...other stuff
<resource-file src="GoogleService-Info.plist" target="resources/GoogleService-Info.plist" />
和其他插件示例...
<edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
<string>need camera access to take pictures</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSPhotoLibraryUsageDescription">
<string>need photo library access to get pictures from there</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
<string>need location access to find things nearby</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSPhotoLibraryAddUsageDescription">
<string>need photo library access to save pictures there</string>
</edit-config>
<resource-file src="GoogleService-Info.plist" target="resources/GoogleService-Info.plist" />
<config-file parent="NSMainNibFile" platform="ios" target="*-Info.plist">
<string />
</config-file>
<config-file parent="NSMainNibFile~ipad" platform="ios" target="*-Info.plist">
<string />
</config-file>
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
</platform>