I am searching about "How to implement PFquery in ios ?"
I am getting followings links. I am fresher in ios field and I don't understand that..
this link for discription of PFquery
this link for discription of PFquery
Please Help me any one know any tutorial for learning and implementing in iphone app.
PFQuery *query = [PFQuery queryWithClassName:#"UserInfo"];
[query selectKeys:#[#"FirstName"]];
NSArray *results = [query findObjects:nil];
NSLog(#"%#",[results description]);
And Check this link its all about PFQuery
Example:
PFQuery *query = [PFQuery queryWithClassName:#"tempClass"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded. The first 100 objects are available in objects
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
Good starter: Parse with TableView
Related
I'm using the anonymous user feature of Parse so that each user can create a "Favorite" list and not have to create an account on the app.
When a user is on an item detail page there will be a "Star" image and when selected that object should be added to their Favorite List, which will be a table on another UIViewController.
Here's my code when adding to favorites:
PFQuery * query = [PFQuery queryWithClassName:#"ClassA"];
[query whereKey:#"item_name" equalTo:self.itemLabel.text];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (error)
{
NSLog(#"Error: %#", error);
}
else
{
PFUser * user = [PFUser currentUser];
self.favRelation = [user relationforKey:#"favorite"];
[self.favRelation addObject:object];
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error)
{
NSLog(#"Error: %# %#", error, [error userInfo]);
}
else
{
NSLog(#"Yay!!");
}
}];
}
}];
When this code runs, the Relation was added to my User table in Parse, but when I select "View Relations", I just see the User again.
Am I over looking something or missing something?
I have to update multiple records in a table on parse.com. It is related to change message status from unread to read in multiple records.
This is the example to update a single record.
PFQuery *query = [PFQuery queryWithClassName:#"GameScore"];
// Retrieve the object by id
[query getObjectInBackgroundWithId:#"xWMyZ4YEGZ" block:^(PFObject *gameScore, NSError *error) {
// Now let's update it with some new data. In this case, only cheatMode and score
// will get sent to the cloud. playerName hasn't changed.
[gameScore setObject:[NSNumber numberWithBool:YES] forKey:#"cheatMode"];
[gameScore setObject:[NSNumber numberWithInt:1338] forKey:#"score"];
[gameScore saveInBackground];
}];
How to update multiple records?
For more clarification,I have to execute query something like :
Update tableName SET messageStatus = 'read' Where userId = 'someId'
Any help ?
First you should query these objects:
NSArray *arrayOfMessageIDs = #[#"2314312", #"312432423"]; // An array of your desired messages' ID
PFQuery *query = [PFQuery queryWithClassName:#"Message"];
[query whereKey:#"messageID" containedIn:arrayOfMessageIDs];
Then you iterate through them and update their status.
After that you save all the array.
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if (error) {
NSLog(#"%#", error);
return;
}
for (PFObject *message in objects) {
// Update your message
}
int success = [PFObject saveAll:objects];
NSLog(#"Status %#", success? #"updated successfully": #"update failed");
}];
If it is a big number of records I suggest you to execute the update via cloud code. What you need to do is to query and receive a list of records then iterate through the list, update the records and then save the records.
you can find information about cloud code at https://www.parse.com/docs/cloud_code_guide.
Duplicate of :
https://stackoverflow.com/questions/17037149/ios-parse-com-app-crashes-while-retrieve-data-from-cache-nsinternalinconsiste
have implemented an iOS App using Parse.com
Trying to retrieve from cache.
While retrieve data from cache i got an error like this:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This query has an outstanding network connection. You have to wait until it's done.'
When i browse for the issues i found that:
Some suggested that it may happens due to making two query calls on the same query object without waiting for the first to complete.
how to avoid these simultatanius calls in this app
query setLimit: limit];
[query setSkip: skip];
//RETRIEVING FROM CACHE
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error)
{
[allObjects removeAllObjects]; //Added regarding cache ******
// The find succeeded. Add the returned objects to allObjects
[allObjects addObjectsFromArray:objects];
if (objects.count == limit) {
// There might be more objects in the table. Update the skip value and execute the query again.
skip += limit;
[query setSkip: skip];
// Go get more results
weakPointer();
}
else
{
// We are done so return the objects
block(allObjects, nil);
}
}
else
{
block(nil,error);
}
}];
To avoid simultaneous calls of a PFQuery, call [query cancel] before findObjects is called:
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
[query cancel]; //cancels the current network request being made by this query (if any)
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
//do stuff
}];
Careful:
[query cancel];
Does not work if you're expecting the callback.
Solution:
#property (nonatomic) BOOL isCurrentlyFetching; // Makes sure Parse is called only
-(void)myQuery
{
if (_isCurrentlyFetching) { return; } // Bails if currently fetching
_isCurrentlyFetching = YES;
//RETRIEVING FROM CACHE
query.cachePolicy = kPFCachePolicyCacheThenNetwork; // Whatever your cache policy is
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error){
// Your code...
}
else{
// Your code...
}
_isCurrentlyFetching = NO;
}];
}
I have the following tables name "aniStudii" and "discipline", I have made a screenshot as well:
As you can see, there is a relation between these tables, at the "materii" column. The row from "aniStudii" with the column "Anul I" has a value and the other column has a different value, values that can be found in the "discipline" table.
I am using this query to get the values, but all I get is Error: bad pointer for key: _p_materii (Code: 106, Version: 1.2.8)
This is my query:
PFQuery *query = [PFQuery queryWithClassName:#"aniStudii"]; //1
PFObject *aniStudiu = [PFObject objectWithClassName:#"discipline"];
[query whereKey:#"materii" equalTo:aniStudiu];
[query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
NSLog(#"%#",results);
}];
Where is the problem? A big thanks in advance.
Do something like this, where you start from a specified object (which you may need a query to find):
PFObject *sourceObject = ...;
PFRelation *relation = [sourceObject relationforKey:#"materii"];
[[relation query] findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
NSLog(#"%#",results);
}];
To get the first object you can perform a query something like:
PFQuery *query = [PFQuery queryWithClassName:#"aniStudii"];
[query whereKey:#"numeAn" equalTo:#"######"];
I am using parse for my iPhone app, and I am trying to fetch a PFObject using PFQuery. My query and other related code is as follows:
PFQuery *query = [PFQuery queryWithClassName:#"UserInfo"];
[query whereKey:#"userId" equalTo:#"89b7eb8801b24ace16b35b927ef01d4f"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(#"Successfully retrieved %d users.", objects.count);
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
I tried using this method but I am getting 0 results in NSArray objects. While you can see in my data browser that there is one object matching the userId. I am able to add data in that class, but I am not able to retrieve it. Am I missing something? I am new at using Parse.
I got it. It was the anonymous user being created from my appDidFinishLaunching method.
This code was running which I wasn't aware of:
[PFUser enableAutomaticUser];
PFACL *defaultACL = [PFACL ACL];
// Optionally enable public read access by default.
[defaultACL setPublicReadAccess:YES];
[PFACL setDefaultACL:defaultACL withAccessForCurrentUser:YES];
Now, initially the [defaultACL setPublicReadAccess:YES]; line was commented. I studied a bit about users and anonymous users being created and uncommented this line, and it worked just fine exactly as I wanted. The PFQuery has started returning results. So, I am assuming the defaultACL value was the issue. Please correct me if wrong.