我正在iOS中设置shareExtension,并希望使用FirebaseSDK直接上传数据,而不是使用AppGroups。这工作如预期,但一个小时后,UserToken的get是无效的,我不能再到达Firestore后端。
我使用FirebaseSDK (6.2.0)并启用了密钥链共享来访问当前的signedIn用户。我在MainApp和shareExtension中有相同的Google-Plist。数据也可以从shareExtension正确上传,并且还可以通过MainApp中的snapshotListener进行更新。
MainApp中的相关代码
lazy var db = Firestore.firestore()
//TEAMID form the Apple Developer Portal
let accessGroup = "TEAMID.de.debug.fireAuthExample"
override func viewDidLoad() {
super.viewDidLoad()
do {
try Auth.auth().useUserAccessGroup("\(accessGroup)")
} catch let error as NSError {
print("Error changing user access group: %@", error)
}
guard let user = Auth.auth().currentUser else {
self.statusLabel.text = "user get's lost"
return
}
statusLabel.text = "UserID: \(user.uid)"
// Do any additional setup after loading the view.
db.collection("DummyCollection").addSnapshotListener { (querySnapshot, error) in
if let err = error {
print(err.localizedDescription)
}
guard let snapshot = querySnapshot else {
return
}
DispatchQueue.main.async {
self.dbCountLabel.text = "\(snapshot.count)"
}
}
}
func signIN(){
// https://firebase.google.com/docs/auth/ios/single-sign-on
do {
try Auth.auth().useUserAccessGroup("\(accessGroup)")
} catch let error as NSError {
print("Error changing user access group: %@", error)
}
Auth.auth().signInAnonymously { (result, error) in
if let err = error{
print(err.localizedDescription)
return
}
print("UserID: \(Auth.auth().currentUser!.uid)")
}
}
}
} shareExtension中的代码:
override func viewDidLoad() {
super.viewDidLoad()
if FirebaseApp.app() == nil {
FirebaseApp.configure()
}
do {
try Auth.auth().useUserAccessGroup(accessGroup)
} catch let error as NSError {
print("Error changing user access group: %@", error)
}
tempUser = Auth.auth().currentUser
if tempUser != nil {
userIDLabel.text = "UserID: \(tempUser!.uid)"
doneButton.isEnabled = true
db.collection("DummyCollection").addSnapshotListener { (querySnapshot, error) in
if let err = error {
print(err.localizedDescription)
}
guard let snapshot = querySnapshot else {
return
}
DispatchQueue.main.async {
self.dataCountLabel.text = "\(snapshot.count)"
}
}
} else {
// No user exists in the access group
self.navigationItem.title = "No User"
}
}我希望这应该是可能的,但令牌在MainApp中不知何故变得无效,并且我无法到达Firestore后端。
6.2.0 - Firebase/Auth令牌自动刷新重新安排在01:00,因为在之前的刷新尝试中出现错误。
6.2.0 - Firebase/Firestore无法访问Cloud Firestore后端。连接失败%1次。最新错误:发生内部错误,请打印并检查错误详细信息以了解更多信息。
发布于 2019-07-04 20:29:09
回答我自己的问题:这个问题应该在下一个版本(Firebase 6.4.0) Details can be found in this PR 3239中修复。
https://stackoverflow.com/questions/56490131
复制相似问题