【问题标题】:Firebase Storage Error - FIRStorageErrorDomain Code=-13021 "User does not have permission to access"Firebase 存储错误 - FIRStorageErrorDomain Code=-13021 “用户没有访问权限”
【发布时间】:2022-04-24 15:54:22
【问题描述】:

我遇到了一个问题,我已经处理了一段时间了。基本上我试图从 Firebase 存储中抓取图像到我的 UICollectionView 中。

当我选择那个 VC 时,只有 90% 的图像加载。当我向下滚动并向上滚动时,其余负载..我不知道为什么。

这是错误代码:

ResponseErrorDomain=com.google.HTTPStatus, data=<7b0a2020 22657272 6f72223a 207b0a20 20202022 636f6465 223a2034 30332c0a 20202020 226d6573 73616765 223a2022 44657665 6c6f7065 72206372 6564656e 7469616c 73207265 71756972 65642e22 0a20207d 0a7d>, bucket=project-355640.appspot.com, ResponseErrorCode=403, NSLocalizedDescription=User does not have permission to access gs://project-355640.appspot.com/(null).})
Optional(Error Domain=FIRStorageErrorDomain Code=-13021 "User does not have permission to access gs://project-3550640.appspot.com/(null)." UserInfo={ResponseBody={
  "error": {
    "code": 403,
    "message": "Developer credentials required.

以下是单元格的创建方式:

 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("StoreViewCell", forIndexPath: indexPath)



        if let view = cell as? storeViewCell {

            //Problem is that every time we scroll the images are reloaded from server.
            /// See if yo ucan cache the images somehow and only use those images or cancel the reload.


            view.storeGunName.text = self.playerData.basicGunDict[indexPath.item]["model"]
            view.storeGunPrice.text = "$\(self.playerData.basicGunDict[indexPath.item]["price"]!)"

            if self.playerData.basicGunDict[indexPath.item]["available"] == "yes" {

                let currentImg = storageRef.child(self.playerData.basicGunDict[indexPath.item]["u-image"]!)

                currentImg.dataWithMaxSize(1 * 1024 * 1024, completion: {
                    (data, error) -> Void in

                    if (error != nil) {
                        print(error.debugDescription)
                    } else {
                        view.storeGunImage.image = UIImage(data: data!)
                    }

                })


            } else {

                let currentImg = storageRef.child(self.playerData.basicGunDict[indexPath.item]["l-image"]!)

                currentImg.dataWithMaxSize(1 * 1024 * 1024, completion: {
                    (data, error) -> Void in

                    if (error != nil) {
                        print(error.debugDescription)
                    } else {
                        view.storeGunImage.image = UIImage(data: data!)
                    }

                })

            }


            print("PER CELL \(self.playerData.basicGunDict[indexPath.item])")

        }
        return cell
    }



service firebase.storage {
  match /b/project-3550640.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

【问题讨论】:

  • 我没有使用 Firebase 存储,但是当我的规则设置不正确时,我看到了 Firebase 数据库的类似问题。我会检查您在 Firebase 控制台中设置的规则。
  • @chickenparm 我用我的 Firebase 存储规则更新了代码。看看能不能看出问题!谢谢你:)
  • 抱歉,我不太擅长 Firebase 规则。希望其他人可以审查。
  • 你有电话重新加载你的collectionView吗?您是否验证了您的 APNS 设置?
  • @tymac 不,我没有。我应该在 ViewWillAppear 中放一个吗?至于推送通知,我没有,因为我认为我的游戏不需要它。我需要它来正确显示图像吗?

标签: swift


【解决方案1】:

Firebase 控制台 -> 存储 -> 规则

如果为假则更改 -> 如果为真

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true; // change here
    }
  }
}

【讨论】:

    最近更新 更多