0
votes

I'm struggling with saving a PFObject: trip is a property on a UIViewController, it is of type UNTrip a subclass of PFObject. My App downloads a trip created by another user. As soon as I change a property on this trip and then try to save it with saveInBackgroundWithBlock I get the error "object not found". I made sure that both sending and receiving users have write access, which I checked in the Parse console. I also tried with public write access to no avail, so that's apparently not the issue.

The objectId is not touched, so that can't be the issue either.

This is what the console shows:

(PFObject) Parse.PFObject = { NSObject = { isa = Unter.UNTrip } dirty = false operationSetQueue = 0x0000000171651f10 "1 value" estimatedData = 0x0000000171653290 5 key/value pairs lock = 0x00000001702157c0 hasBeenFetched = true _dataAvailability = 0x0000000171651f40 4 key/value pairs _isDeleted = false _deletingEventually = 0 serverData = 0x0000000171651a90 5 key/value pairs hashedObjectsCache = 0x00000001716524b0 2 key/value pairs updatedAt = 0x0000000170215810 2015-05-17 14:23:29 UTC createdAt = 0x0000000170215800 2015-05-17 14:23:29 UTC localId = nil objectId = 0x000000017063e860 "M4WqMOFtMn" parseClassName = "UNTrip" createdAsPointer = true _eventuallyTaskQueue = 0x000000017063dbc0 saveDelegate = nil taskQueue = 0x000000017063db40 }

UNTrip class: class UNTrip: PFObject, PFSubclassing, Printable{

The trip is successfully saved by user A in the cloud, setting write access for both users A and B (respondingUser):

  func saveTripToCloud(trip: UNTrip){
// Find user
let userQuery = PFUser.query()
userQuery?.whereKey("email", equalTo: trip.respondingUser!.email)
userQuery?.getFirstObjectInBackgroundWithBlock({ (object: PFObject?, error: NSError?) -> Void in
    if let respondingUser = object as? PFUser {
      println("First user: \(respondingUser.username)")
      trip.ACL?.setWriteAccess(true, forUser: respondingUser)
      trip.ACL?.setWriteAccess(true, forUser: PFUser.currentUser()!)

      trip.saveInBackgroundWithBlock{(success: Bool, error: NSError?) -> Void in

User B successfully retrieves the trip from the cloud after receiving a push with the objectId (includeKey to also retrieve other stored PFObjects):

    if let objectId = userInfo["objectId"] as? String {
  var query = PFQuery(className: "UNTrip")
  query.includeKey("requestingUser")
  query.includeKey("respondingUser")
  query.getObjectInBackgroundWithId(objectId, block: { (object: PFObject?, error: NSError?) -> Void in

User B then changes one of the properties on trip (use of self because it's done in a completion block):

self.trip?.respondingUser?.travelTime = travelTime

User B is then UNsuccessful in trying to save trip back to the cloud via:

trip?.saveInBackgroundWithBlock({ (succes:Bool, error: NSError?) -> Void in

success: false, error: object not found

Can somebody shed some light?

1
need to see the code - danh

1 Answers

1
votes

Phew, finally solved this one.

When User B receives a trip, it changes the property trip.respondingUser.travelTime. respondingUser is another PFObject subclass instance created by User A. I forgot to give User B write access to that PFObject subclass instance before sending it over to User B by including this line of code: trip.respondingUser?.ACL?.setWriteAccess(true, forUser: respondingUser) where respondingUser is a PFUser instance referring to User B, the user that receives the trip.

Problem solved, thanks for having a look.