在更新到最新的Xcode(10.2.1)并使用“ pod update”更新了pod之前,我的iOS应用一直有效。我以前使用的是Xcode 9.4.1和Swift3。我进行了更新,因为无法使用该版本的Xcode上传到应用商店。
其余功能正常运行(包括firebase电话身份验证),但绝不会触发所有“ Observe” firebase数据库功能。它构建成功,并且没有显示错误。
我尝试没有成功:
-从firebase下载plist文件。
-将数据库规则设置为true以进行读写。
-将“部署目标”设置为11.0和podFile平台:ios,“ 11.0”
podFile:
platform :ios, '12.0'
target 'appname' do
use_frameworks!
pod 'Firebase/Database'
pod 'Firebase/Auth'
pod 'Firebase/Storage'
pod 'SwiftyStoreKit'
pod 'Onboard'
pod 'SDWebImage'
pod 'IQKeyboardManagerSwift'
end
在AppDelegate中初始化Firebase-didFinishLaunchingWithOptions:
FirebaseApp.configure()
在此之前一切都按预期进行:
Auth.auth().signIn(with: credential) { (user,error) in
if error != nil {
print(error)
} else {
print(phone number: \(String(describing: user?.user.phoneNumber))")//this is successfully printed
let userInfo = user?.user.providerData[0]
print(Provider ID: \(String(describing: userInfo?.providerID))")//this is successfully printed
if let user = Auth.auth().currentUser {
let uid = user.uid
let ref = Database.database().reference()
ref.child("users").observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.hasChild(uid) {
print("user already exists")//this never gets printed
} else {
let values: [String: AnyObject] = ["phoneNumber": user.phoneNumber as AnyObject]
let userRef = ref.child("users").child(uid)
userRef.updateChildValues(values, withCompletionBlock: { (err,ref) in//user never gets created in database but it is created in firebase
if err != nil {
print(err)
return
}
})
}
let tabBarController = CustomTabBarController()//this never gets executed
present(tabBarController, animated: true)
})
}
}
}
答案 0 :(得分:0)
问题是cocoapods版本,我有1.5.3。一旦我更新到1.7.2,一切都会按预期进行。