PFUser Query Contraint - parse-platform

This is my current query:
[PFQuery *userQuery = [PFUser query];
[userQuery whereKey:#"phone" containedIn:phones];
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
self.contactsWithApp = objects;
[self.tableView reloadData];
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
I am searching for users according to an array composed of phone number strings. The key 'phone' in my User class contains a phone number string for each user. Why is this not working?

Try using this instead. This is assuming that the class you are querying in Parse is called User.
Replace your line of:
PFQuery *userQuery = [PFUser query];
With this:
PFQuery *userQuery = [PFQuery queryWithClassName:#"_User"];
Final code:
PFQuery *userQuery = [PFQuery queryWithClassName:#"_User"];
[userQuery whereKey:#"phone" containedIn:phones];
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
self.contactsWithApp = objects;
[self.tableView reloadData];
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];

I'm pretty sure that this question isn't actual anymore. But I faced with the same problem and want to share with solution. Most likely that you have got JSON response, and your 'phone' in phones - is NSNumber type. To query from Parse with containedIn: array must be with objects of type NSString.

Related

CloudKit Query Value Limit Error

I have a query with a predicate in which I want to see if any values inside an array are contained in a CKRecord on CloudKit, but when I execute the query I get an error saying "Query filter exceeds the limit of values: 250 for container"
Is there another way to query my array? It has 500 objects in it, but it's dynamic so depending on the user it could be a lot less or a lot more.
CKDatabase *publicDatabase = [[CKContainer defaultContainer] publicCloudDatabase];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"PhoneNumber == %#", numbers1];
CKQuery *query = [[CKQuery alloc] initWithRecordType:#"PhoneNumbers" predicate:predicate];
[publicDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {
if (error) {
NSLog(#"%#", error);
}
else {
NSLog(#"%#", results);
}
}];

Parse.com PFQuery & Cache crash my app

Hello everyone I am using parse.com In my app .
To get SOME data and run a PFQuery In research I added also
[userQuery setCachePolicy:kPFCachePolicyCacheThenNetwork];
So far so good , but when you run the ' application crash and do not understand why ... If I remove the search function of the cache in the app does not crash .
Someone can ' help me understand a thing happens ?
This is my query
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:kUNIUserLastNameKey equalTo:[currentUser objectForKey:kUNIUserLastNameKey]];
[userQuery setCachePolicy:kPFCachePolicyCacheThenNetwork];
[userQuery findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
if (!error) {
NSMutableArray *nameArray = [[NSMutableArray alloc] init];
for (PFObject *object in objects) {
[nameArray addObject:object];
NSString *welcome = [NSString stringWithFormat:#"welcome %#!", [object objectForKey:kUNIUserLastNameKey]];
}
}
}];

How to login as a PFUser/ParseUser when internet is unavailable?

Im trying to run my Login app offline.I initially enabled local datastore and then have retrieved users online and pinned them like this:
PFQuery *query = [PFUser query];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded. The first 100 objects are available in objects
[PFObject pinAllInBackground:objects];
NSLog(#"%#", objects);
PFUser *user =[objects objectAtIndex:1];
NSLog(#"%#",user.username);
NSLog(#"%#",user.password);
NSLog(#"%#",user.email);
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
After That I tried to login without internet but PFLoginViewController shows the following error:
[Error]: The Internet connection appears to be offline. (Code: 100, Version: 1.7.1)

How do I add a NSNumber fetched object from Parse to a NSMutable array?

I have a normal Parse query and inside the query i have this piece of code that basically fetched all objects found:
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(#"Successfully retrieved %lu scores.", (unsigned long)objects.count);
// Do something with the found objects
for (NSObject *object in objects){
NSLog(#"vacants %d ", [[object valueForKey:#"Vacants"]intValue]);
[eventnameArray addObject:[object valueForKey:#"EventName"]];
[userArray addObject:[object valueForKey:#"Username"]];
[sportArray addObject:[object valueForKey:#"Sportname"]];
[hourArray addObject:[object valueForKey:#"Hour"]];
[dateArray addObject:[object valueForKey:#"Date"]];
[placeArray addObject:[object valueForKey:#"Place"]];
[vacantsArray addObject: [NSNumber numberWithInt:[object valueForKey:#"Vacants"]]];
[cityArray addObject:[object valueForKey:#"City"]];
}
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
[self.tableView reloadData];
}];
For Vacantsarray the fetched value from the Parse Cloud in a number. I cannot seem to be able to add this numeric value to the NSMutablearray
It throws me this error:
-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance
EDIT :
Doing this:
[vacantsArray addObject: [NSString stringWithFormat:[object valueForKey:#"Vacants"]]];
throws me this error:
-[__NSCFNumber length]: unrecognized selector sent to instance
Use NSString stringWithFormat to convert NSNumber before perform any operations like isEqualToString.
I could solve it by doing this :
[vacantsArray addObject: [(NSNumber*)[object valueForKey:#"Vacants"] stringValue]];

is it possible to update and save a pfobject from a query using parse?

Is it possible to do this:
PFQuery *query = [PFQuery queryWithClassName:#"GameScore"];
[query whereKey:#"playerName" equalTo:#"Dan Stemkoski"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// THis is the part that isn't working
PFObject *pTeam = objects[0];
[pTeam setObject:#"new team name" forKey:#"team"];
[pTeam saveInBackground];
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
When I update the found query object and save, it is not saved to the server.
Is what I am doing possible and if so what am I doing wrong?
Try the below one, it works for me.
PFObject *pTeam = [PFObject objectWithoutDataWithClassName:"GameScore" objectId: [object[0] objectId]];
[pTeam setObject:#"new team name" forKey:#"team"];
[pTeam saveInBackground];

Resources