I didn't have this issue when my app was hosted on Parse.com. I have upgraded to sdk 1.12.0 and am hosting my app locally and on Heroku. Here is my appDelegate:
`- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Parse enableLocalDatastore];
[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> _Nonnull configuration) {
configuration.applicationId = @"MY_APP_ID";
configuration.clientKey = @"MY_CLIENT_KEY";
configuration.server = @"https://localhost:5000"/parse;
}]];
`
The error gets thrown when I run the following code:
- (void)updateLocalDataStore
{
PFQuery *query = [PFQuery queryWithClassName:@"Project"];
[[query fromLocalDatastore] ignoreACLs];
}
But if I add [Parse enableLocalDatastore] in that function, it works fine. But I'm getting "Method requires Pinning enabled" errors all over my app, which means I'd have to paste that line everywhere. Why isn't the first instance of enabling the local datastore "sticking"?
Hey @lususvir, since you are using the new ParseClientConfiguration API in order to enable JSON change your initialization to something like this:
[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> _Nonnull configuration) {
configuration.applicationId = @"MY_APP_ID";
configuration.clientKey = @"MY_CLIENT_KEY";
configuration.server = @"https://localhost:5000"/parse;
configuration.localDatastoreEnabled = YES;
}]];
The difference is in adding the line configuration.localDatastoreEnabled = YES;. Any calls to the old APIs if you are using the client configuration actually wouldn't work, since all properties are overridable via configuration and it always is going to use the latter.
Hope this helps, let me know how it goes or if there is anything I could help you with.
Thank you, that solved it.
That solved the crashing for me, but I'm still unable to query from the localDataStore.
if ([AppD weAreOnline] == false) {
[query fromLocalDatastore];
}
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
[PFObject pinAllInBackground:objects];
_transactions = [NSMutableArray arrayWithArray:objects];
[_transactions insertObject:@"New Document" atIndex:0];
[self.tableView reloadData];
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
CLog(@"setFormInfo Error during Parse Query: %@ %@", error, [error userInfo])
}
}];
I tried by doing the PFQuery while online, then pinAllInBackground all the objects I received.
Then I switched to airplane mode. This time, the [query fromLocalDatastore]; was fired because weAreOnline is false.
error was nil, but so was the objects. While online it returned 26 items, then offline it returned nil.
This code has been working while I was on api.parse.com and using 1.12.x API. Now that I migrated to my own parse-server and using 1.14.2, it now gives me nil.
Hope to hear from you guys. Thank you!
Most helpful comment
Hey @lususvir, since you are using the new
ParseClientConfigurationAPI in order to enable JSON change your initialization to something like this:The difference is in adding the line
configuration.localDatastoreEnabled = YES;. Any calls to the old APIs if you are using the client configuration actually wouldn't work, since all properties are overridable via configuration and it always is going to use the latter.Hope this helps, let me know how it goes or if there is anything I could help you with.