【发布时间】:2017-02-26 13:05:27
【问题描述】:
在我的 iOS 应用中,用户可以通过搜索唯一的用户名来添加朋友。
用户在 textField 中输入用户名,我有一个 textFieldDidChange 通知,每次文本更改时都会触发。
然后我在该方法中调用下面的 Firebase 方法来检查用户名是否存在。
func searchFor(_ username: String) {
guard let uid = FIRAuth.auth()?.currentUser?.uid else {
return
}
let lowercaseUsername = username.lowercased()
let ref = FIRDatabase.database().reference()
ref.child(FirebaseDatabaseBranchNames.usernames.rawValue).child(lowercaseUsername).observeSingleEvent(of: .value, with: { [unowned self](snapshot) in
if snapshot.exists() {
if let usernameUid = snapshot.value as? String {
self.isUserAlreadyAFriend(ref, uid: uid, usernameUid: usernameUid)
}
} else {
// username doesn't exist
}
}, withCancel: nil)
}
如何在再次执行之前取消此方法?
【问题讨论】:
标签: ios firebase firebase-realtime-database