小编Jay*_*Jay的帖子

Firebase快速检查现有用户

我有VC,在这里我要创建一个新用户并添加到firebase中。用户不会在数据库中插入任何问题,但是我无法检查是否存在具有相同名称的用户。我尝试在firebase中使用各种查询语句,但没有获得任何乐趣。有谁知道我可以如何修改我的代码来实现这一目标?这里是 :-

 @IBAction func submitUsername(sender: AnyObject) {

    if let user = usernameTxtField.text where user != "" {

       let username = DataService.ds.REF_USERS.childByAppendingPath("username")

       username.observeSingleEventOfType(.Value, withBlock: {  snap in

            if let usernameDoesNotExist = snap.value as? NSNull {
              let currentUser = DataService.ds.REF_USER_CURRENT.childByAppendingPath("username")
              self.usernameTxtField.text = user
              currentUser.setValue(user)
            }
       })

       dismissViewControllerAnimated(true, completion: nil)

    } else {
        showAlert("Username Needed", msg: "please choose a username")
    } 
}
Run Code Online (Sandbox Code Playgroud)

和firebase数据结构

"users" : {
    "000591b6-ba88-4670-9cb7-edd79c273eab" : {
      "newuser" : "added to FB",
      "provider" : "password"
    },
    "05551c90-27fe-4969-b45d-279a72583857" : {
      "newuser" : …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift

2
推荐指数
1
解决办法
2554
查看次数

Firebase安全规则,用于管理员写入和读取数据库中的所有内容

我试图让我的自己能够读写数据库中的所有内容.

尝试在firebase模拟器中运行时,我收到读取被拒绝错误.

{
  "rules": {

    ".read": "root.child('Admin').child('isAdmin').child('+$AUID').val() === true",

    "Admin": {
      "isAdmin": {
        "$AUID": {

          ".read": "$AUID === auth.uid",
          ".write": "$AUID === auth.uid",
          ".validate": "newData.hasChildren(['active'])",

          "active": {

            "active": "true"
          },
        },
      },
    },
}
Run Code Online (Sandbox Code Playgroud)

firebase firebase-security firebase-realtime-database

2
推荐指数
1
解决办法
2678
查看次数

Swift Firebase 检查用户是否存在

我究竟做错了什么?我有一个像这张图片中显示的那样的数据库结构。 我的数据结构
在 appleDelegate.swift 中,我只想检查“用户”节点下是否确实存在某个用户令牌。也就是说,如果“用户”具有子 currentUserID(字符串标记)。我了解observeSingleEvent 是异步执行的。我在swift 中收到此错误:“应用程序窗口应在应用程序启动结束时有一个根视图控制器”。在“func application(_ application:UIApplication”)中,我有这个代码。我在下面还有我的完成处理程序函数。

if let user = Auth.auth().currentUser{
        let currentUserID = user.uid
        ifUserIsMember(userId:currentUserID){(exist)->() in
            if exist == true{
                print("user is member")
                self.window?.rootViewController = CustomTabBarController()
            } else {
                self.window?.rootViewController = UINavigationController(rootViewController: LoginController())
            }
        }

        return true
    } else {
        self.window?.rootViewController = UINavigationController(rootViewController: LoginController())
        return true
    }
}

func ifUserIsMember(userId:String,completionHandler:@escaping((_ exists : Bool)->Void)){
    print("ifUserIsMember")
    let ref = Database.database().reference()
    ref.child("users").observeSingleEvent(of: .value, with: { (snapshot) in
        if snapshot.hasChild(userId) {
            print("user exists")
            completionHandler(true)
        } else {
            print("user doesn't exist") …
Run Code Online (Sandbox Code Playgroud)

firebase completionhandler swift firebase-realtime-database

2
推荐指数
1
解决办法
2034
查看次数

如何修复 CallKit 目录扩展中的“sqlite3”和其他错误?

context.addIdentificationEntry(withNextSequentialPhoneNumber: contact.number, label: contact.contactLabel)\n该应用程序的想法是将大约 50.000 个联系人添加到 CallKit 目录中,但是当我尝试在方法中添加它们时,beginRequest(with context: CXCallDirectoryExtensionContext)我经常会收到 com.apple.CallKit.error.calldirectorymanager 错误 2 或一些奇怪的 sqlite3 错误:

\n\n
sqlite3_step for query \'INSERT INTO PhoneNumberIdentificationEntry \n(extension_id, phone_number_id, label_id) VALUES (?, (SELECT id \nFROM PhoneNumber WHERE (number = ?)), (SELECT id FROM Label WHERE \n(localized_label = ?))), \n\xe2\x80\xa6\n(SELECT id FROM Label WHERE (localized_label = ?)))\' returned 19 \n(2067) errorMessage \'UNIQUE constraint failed: \nPhoneNumberIdentificationEntry.extension_id, \nPhoneNumberIdentificationEntry.phone_number_id, \nPhoneNumberIdentificationEntry.label_id\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

一般来说,我从服务器获取联系人并尝试使它们保持同步 - 因此,我使用 Realm 将它们保存在本地。有谁知道如何处理此类错误?

\n

sqlite ios swift callkit

2
推荐指数
1
解决办法
732
查看次数

以属于和多对关系的方式构建 Firestore 中的数据

来自 SQL/Rails 背景的我有一个项目,我想使用 Firebase/Firestore(带有 React),并寻求帮助来设置数据和集合结构。

“楷模”:

  • 用户
  • 项目
  • 类别
  • 地点

一个用户可以拥有多个项目,一个项目属于一个用户。一个类别可以有多个项目,一个项目属于一个类别。

我需要能够在主页上显示所有类别、位置和项目。首先,我需要列出所有项目,并且可以按类别和/或位置过滤它们。

如何在 Firestore 中最好地设置该数据?

抱歉我用的是 Rails 风格的解释,但我脑子里全是 SQL。

firebase react-native google-cloud-firestore

2
推荐指数
1
解决办法
1398
查看次数