首页 > 解决方案 > Firebase 无法连接到服务器

问题描述

我正在尝试将我的应用连接到 Firebase。我按照执行此操作的步骤进行操作。我在 Firebase 中创建了一个项目。我下载了 Google services.info 文件。我将我的 pod 文件放入项目中。该项目在 Xcode 中运行,但它不允许我将 Firebase 项目连接到服务器。

以下是我收到的错误消息。我什至在 Safari 中清除了我的缓存,但似乎没有任何效果。在我的应用程序委托中,我是否正在尝试测试我的项目以查看是否在 Firebase 数据库中检测到它。以下是我在 Xcode 控制台中收到的错误。

":ResponseBody={
  "error": {
    "code": 400,
    "message": "Permission denied. Could not access bucket sya2-moments-1e2c9.appspot.com. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources."
  }
}, "

代码:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()

        let dummyUser = User(uid: "123", username: "myUserNameDummy", bio: "My Dummy User", fullName: "My Dummy User", website: "My Dummy User", follows: [], followedBy: [], profileImage: UIImage(named: "1"))
        dummyUser.save { (error) in
            print(error)
        }

        return true
    }
}

标签: iosswiftfirebasefirebase-storage

解决方案


Just check your Rules in your firebase. If you want to write and read data from your firebase Server then change it to "true" like the image bellow.

enter image description here

and for storage like this :

enter image description here

add the following code to safe something to your firebase in your case a user :

var db: DatabaseReference!

override func viewDidLoad() {
    super.viewDidLoad()
    db = Database.database().reference()
    //        checkForPrivacy()

}

self.db.child("key").setValue(dummyUser, withCompletionBlock: {error ,ref in
    if error != nil{
          print("error")
    }else{
        print("ok")
    }
})

推荐阅读