无法在 localDatastore 中查询固定的子类 PFObject

Can't Query for Pinned Subclassed PFObject in localDatastore

你好,我在从 Parse LocalDataStore 中检索 PFObject 子类时遇到问题,我在固定之前对对象进行了 NSLogged,它看起来很好,它也成功固定了。但是当我在固定对象后去查询对象时,没有任何结果。

下面是我的代码。有人可以帮我取回我的物品吗?

提前致谢。

Job.h

@interface Job : PFObject<PFSubclassing>

/* Set up all properties that we'll need to record jobs */

// Job Details Properties
@property (retain) NSString *name;
@property (retain) NSString *identifier;
@property (retain) NSString *contact;
@property (retain) NSString *address;
@property (retain) NSString *postcode;

+ (NSString *)parseClassName;

@end

----

Job.m

#import "Job.h"
#import <Parse/Parse.h>
#import <Parse/PFObject+Subclass.h>

@implementation Job

@dynamic name;
@dynamic identifier;
@dynamic contact;
@dynamic address;
@dynamic postcode;

+ (NSString *)parseClassName {

  return @"Jobs";
}


@end

----

MyJobsController.m

#import "MyJobsController.h"
#import "Job.h"

@implementation MyJobsController

- (IBAction)addJob:(id)sender {

    Job *jobOne = [[Job alloc] init];

    jobOne.name = @"Company 001";
    jobOne.contact = @"Dave";
    jobOne.identifier = @"001";

    [jobOne pinInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {

        if (succeeded) {

            NSLog(@"Pinned job: %@",job); 

            [self getJobs];           

        }else{

            NSLog(@"Error: %@",error.userInfo);
        }        

 }];
}

- (void)getJobs {

PFQuery *query = [Job query];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {

      NSLog(@"Found Jobs: %@",objects);

    }else{

      NSLog(@"Error: %@",error.userinfo);

    }
  }]; 
}   

----

MyJobsController.h

#import <UIKit/UIKit.h>

@interface MyJobsController : UIViewController

- (IBAction)addJob:(id)sender;

@end

您是否看过来自 parse.com https://parse.com/docs/ios/api/Classes/PFObject.html#//api/name/pinInBackgroundWithBlock 的 api 信息:据我了解,您必须将此查询的来源更改为所有固定对象。 [PFQuery fromLocalDatastore] 或者您可以使用 [PFObject objectWithoutDataWithClassName:objectId:] 创建一个未获取的指针,然后在其上调用 fetchFromLocalDatastorefromLocalDatastore 的参考信息 https://parse.com/docs/ios/api/Classes/PFQuery.html#//api/name/fromLocalDatastore

希望对您有所帮助。