为什么我的自定义User对象(从PFUser子类化)中缺少字段?

时间:2015-11-07 01:20:34

标签: ios objective-c parse-platform

我正在使用Parse作为我的应用程序。我有一个名为 Request 的自定义类,我在Parse和我的本地项目中设置了它。在请求对象上,我有一个用户对象。 用户对象是 PFUser 的子类。当用户发出请求时,会将其发送到服务器并发送给相应的用户以供他们接受或拒绝。提交请求工作正常;一切都在Parse中正确存储。问题是:

提交请求后,我退出当前用户并登录到应该收到刚刚提交的请求的另一个用户帐户。当我登录时,我有一个方法:

+ (void)getIncomingRequestsWithCompletion: (void(^)(NSMutableArray *incomingPendingRequestsArray, NSMutableArray *incomingAcceptedRequestsArray)) complete {
  PFQuery *query = [PFQuery queryWithClassName:@"Request"];
  [query whereKey:@"club" equalTo:[User currentUser] [@"club"]];
  [query findObjectsInBackgroundWithBlock:^(NSArray *incomingRequestsArray, NSError *error) {
      NSMutableArray *incomingPendingRequestsArray = [NSMutableArray new];
      NSMutableArray *incomingAcceptedRequestsArray = [NSMutableArray new];
      for (int i = 0; i < incomingRequestsArray.count; i++) {
        if ([[incomingRequestsArray objectAtIndex:i]acceptedHostUser]) {
            [incomingAcceptedRequestsArray addObject:[incomingRequestsArray objectAtIndex:i]];
        }
        else if (![[[incomingRequestsArray objectAtIndex:i]decliningUsers]containsObject:[User currentUser]]) {
            [incomingPendingRequestsArray addObject:[incomingRequestsArray objectAtIndex:i]];
        }
      }
      complete (incomingPendingRequestsArray, incomingAcceptedRequestsArray);
      NSLog(@"%@",error.description);
  }];
}

运行此方法后,我将获得当前用户的所有传入请求。这个方法很好地返回请求。问题在于我杀了应用程序。如果我终止应用程序,则在用户重新运行应用程序时将运行上述方法。该方法将返回相同数量的请求,

  

然而 用户对象上的所有属性都将丢失   除了objectId和其他一些股票属性    PFUser 对象。

这是杀死应用程序之前打印的对象:

<Request: 0x7fbe20bf5090, objectId: gEnwjj6ZIN, localId: (null)> {
    club = "<Club: 0x7fbe20b74180, objectId: cApBkG9ZFY>";
    message = "";
    requestingUser = "<PFUser: 0x7fbe2043c640, objectId: LIzd2KvDwa>";
}


<PFUser: 0x7fbe2043c640, objectId: LIzd2KvDwa, localId: (null)> {
    club = "<Club: 0x7fbe2088f5f0, objectId: KUa4N7fTgc>";
    email = "spedroza@usc.edu";
    firstName = Sergio;
    handicap = 10;
    headline = "Web Developer at University of Southern California";
    lastName = Pedroza;
    linkedInID = oOoiyTge7O;
    location = "Greater Los Angeles Area";
    phoneNumber = 5629224083;
    profileImageFile = "<PFFile: 0x7fbe208cb900>";
    username = "spedroza@usc.edu";
}

以下是:

<Request: 0x7fe3f3d4cd50, objectId: gEnwjj6ZIN, localId: (null)> {
    club = "<Club: 0x7fe3f3d287e0, objectId: cApBkG9ZFY>";
    message = "";
    requestingUser = "<PFUser: 0x7fe3f3d38b50, objectId: LIzd2KvDwa>";
}


<PFUser: 0x7fe3f3d38b50, objectId: LIzd2KvDwa, localId: (null)> {
}

现在,我在请求对象上有另一个自定义对象。此对象是 Club 对象,无论应用程序是否已被终止,其自定义属性都在对象上。我一直试图调试这几天,除了运气之外什么也没有。任何和所有的想法都非常感谢!

1 个答案:

答案 0 :(得分:2)

如果我理解正确,那么您缺少详细信息的User对象就是requesUser。尝试在调用findObjectsInBackgroundWithBlock:

之前将其添加到查询中
[query includeKey: @"requestingUser"]; (Objective-C)
query.includeKey("requestingUser"); (Swift)

如果你没有在查询中包含对象,Parse只会从其他类中获取对象。