【问题标题】:Parse weird bug in Swift that causes ACL write permissions to change to an objectId解析 Swift 中导致 ACL 写入权限更改为 objectId 的奇怪错误
【发布时间】:2016-01-21 14:46:10
【问题描述】:

首先,这是在向 riderRequest 表中插入一行后我的解析表的样子。插入后,我的公共写入 ACL 默认为 User 表的 objectId。

riderRequest

用户

这是我将新行插入到我的 riderRequest 表中的代码。

var riderRequest = PFObject(className: "riderRequest")
        riderRequest["username"] = PFUser.currentUser()?.username
        riderRequest["location"] = PFGeoPoint(latitude: latitude, longitude: longitude)

        riderRequest.saveInBackgroundWithBlock { (success, error) -> Void in
            if(success)
            {
                self.callUberButton.setTitle("Cancel Uber", forState: UIControlState.Normal)
            }
            else
            {
                self.displayAlert("Could not call uber", message: "Please try again later")
            }
        }

我的代码与修改 ACL 的值无关。 我似乎无法弄清楚,为什么要修改 ACL 值?

任何帮助将不胜感激。 非常感谢您的帮助。

【问题讨论】:

  • 您是否创建了默认 ACL ?
  • 我的默认acl看起来像这样let defaultACL = PFACL();defaultACL.setPublicReadAccess(true)PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser:true)

标签: swift parse-platform swift2


【解决方案1】:

查看您的 AppDelegate。很可能有一个默认 ACL,它看起来像这样

// Enable public read access by default, with any newly created PFObjects belonging to the current user
let defaultACL: PFACL = PFACL()
defaultACL.publicReadAccess = true
PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser: true)

【讨论】:

  • 我的 AppDelegate 中的默认 ACL 代码如下所示 let defaultACL = PFACL(); defaultACL.setPublicReadAccess(true) PFACL.setDefaultACL(defaultACL, withAccessForCurrentUser:true)
  • 我阅读了关于默认 ACL 的解析文档,在我的 RiderRequest 表中插入新行时,你是 setPublicReadAccess(true)setPublicWriteAccess(true) 吗?
  • 这完全一样,但 Parse SDK 版本已过时。 setPublicReadAccess 已更改为属性,如在我的示例中,在最新版本中。然而,这就是导致您拥有公共读取权限但只有当前用户可以写入的原因。如果您想要公开阅读和公开写入,请将这 3 行注释掉。解析默认为公开读写
  • @SwiftEveryday 这完全取决于您以及您想要完成的工作。通常,您不希望其他人能够修改彼此的对象,这意味着公共读取和私有写入(对于用户)。如果你想公开读写,你可以在你的应用程序委托中注释掉默认ACL代码,或者手动将对象的ACL设置为你提到的公开读写
  • 我明白了,我会记住这一点。非常感谢您的帮助和建议,它确实加快了我的学习过程,有像您这样有经验的人来指导我。
猜你喜欢
  • 1970-01-01
  • 2014-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多