【问题标题】:Firebase cannot connect to serverFirebase 无法连接到服务器
【发布时间】:2018-12-09 23:24:18
【问题描述】:

我正在尝试将我的应用连接到 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
    }
}

【问题讨论】:

    标签: ios swift firebase firebase-storage


    【解决方案1】:

    只需检查您的 Firebase 中的规则即可。如果您想从您的 firebase 服务器写入和读取数据,请将其更改为“true”,如下图所示。

    对于这样的存储:

    添加以下代码以在您的用户的情况下为您的 firebase 提供安全保障:

    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")
        }
    })
    

    【讨论】:

    • 导入 UIKit 导入 CoreData 导入 Firebase @UIApplicationMain 类 AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var db: 数据库参考! 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") } })return true }
    • 我放入应用委托我得到错误方法没有覆盖其超类中的任何方法,'UIResponder'类型的值没有成员'viewDidLoad'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 2020-01-24
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 2020-05-05
    • 2014-10-22
    相关资源
    最近更新 更多