Parse.com iOS objectWithoutDataWithObjectId and Local Datastore

123 Views Asked by At

Context: I would like my game app to work completely offline so users don't need an internet connection to start playing (certain features will be disabled without connectivity). To this end I've exported a PFObject subclass of static data from parse.com that I'd like to include in my app bundle so users don't need to download it from parse.com.

Say my PFObject subclass of static data is Foo, and I have another PFObject subclass called Bar with a pointer to Foo. I run all the following in Airplane Mode:

Foo *foo = [Foo objectWithoutDataWithObjectId:@"someObjectIdFromServer"];
foo.someKey = @"someValue";

Bar *bar = [Bar object];
bar.foo = foo;
[bar pinInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {

    if (succeeded && !error) {

    // Now I query from the local datastore:

    PFQuery *query = [Bar query];
    [query includeKey:@"foo"];
    [query fromLocalDatastore];
    [query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
        if (!objects || error) {
            // error
        } else {
            Bar *bar = [objects firstObject];
            NSLog(@"bar.foo: %@", bar.foo); // this prints the object out fine
            NSLog(@"bar.foo.isDataAvailable: %d", bar.foo.isDataAvailable); // this is 0, even though I called [query includeKey:@"foo"];
            NSLog(@"bar.foo.someKey: %@", bar.foo.someKey); // this silently doesn't return.  No exception raised or nil value, execution just stops here
            NSLog(@"more logging");  // this doesn't print but program execution continues
            [bar.foo fetchFromLocalDatastoreInBackground];  // trying this just in case
            NSLog(@"bar.foo.isDataAvailable: %d", bar.foo.isDataAvailable); // still 0 even with fetch
        }
    }];
  }
}];

Any idea why bar.foo.isDataAvailable is 0, even though I called [query includeKey:@"foo"] and even fetch? My understanding is that objectWithoutDataWithObjectId can be used to create local copies of objects in the parse cloud that can then be used in pointer relationships. Am I misunderstanding what can be done with these objects when only using the local datastore (i.e. in airplane mode)?

Also I've tried the same thing without using objectWithoutDataWithObjectId (instead doing [Foo object]) and that works fine. I can potentially use this in a workaround (along with some Cloud Code to ensure uniqueness on my static data), but I'd prefer not to since that counts towards my Cloud Data quota.

Any feedback is very appreciated!

0

There are 0 best solutions below