加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在swift中为新的Parse用户设置ACL

发布时间:2020-12-14 04:36:51 所属栏目:百科 来源:网络整理
导读:我目前遇到的问题是用户可以访问我的应用中的其他用户的对象. 我知道当用户在已经登录到应用程序时创建对象时如何设置ACL,但我不知道如何为注册的人设置ACL.当我设置导航标题以显示用户的[“BusinessName”]列时,我从另一个创建的用户列中收到商家名称….感
我目前遇到的问题是用户可以访问我的应用中的其他用户的对象.

我知道当用户在已经登录到应用程序时创建对象时如何设置ACL,但我不知道如何为注册的人设置ACL.当我设置导航标题以显示用户的[“BusinessName”]列时,我从另一个创建的用户列中收到商家名称….感谢您的帮助!非常感激!

@IBAction func signupFinalButton(sender: AnyObject) {

  var newUser = PFUser()
  newUser.username = username
  newUser.password = password
  newUser.email = email
  newUser["FirstName"] = firstName
  newUser["LastName"] = lastName
  newUser["BusinessName"] = businessName
  newUser["City"] = city
  newUser["State"] = state

  // This isn't seeming to work...
  newUser.ACL = PFACL(user: PFUser.currentUser()!) 
  or this 
  newUser.ACL = PFACL(user: PFUser())

  newUser.signUpInBackgroundWithBlock({ (succeed,error) -> Void in

或者我查询解析错误?我是新手.

func navTitle () {
     var user = PFUser.currentUser()
     var query = PFQuery(className:"_User")
     query.findObjectsInBackgroundWithBlock {
    (objects: [AnyObject]?,error: NSError?) -> Void in

     if error == nil {
     if let objects = objects as? [PFObject] {
     for object in objects {

     self.homeScreen.title = object["BusinessName"] as! String?
      }
     }else {

     self.homeScreen.title = "Home"
     }

解决方法

您需要在signUp完成后设置ACL.

所以在委托方法中,

func signUpViewController(signUpController: PFSignUpViewController,didSignUpUser user: PFUser)

// set the ACL for the newly created user

newUser.ACL = PFACL(user: PFUser.currentUser()!)

//Then you can save the user,ie saveEventaully

如果您没有使用PFSignUpViewController – 只需在signUpInBackgroundWithBlock的代码块中设置ACL,则在设置后调用save.

当您想要创建角色时,这是相同的,用户需要已经存在.

这是在同一方法体中创建角色的方法

let role = PFRole(name: user.objectId!,acl: roleACL)
role.users.addObject(user)

首次学习解析时,我建议通过this method创建新用户.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读