Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Self-Destructing Message iPhone App Retrieving and Viewing Data from Parse.com Retrieving Data from Parse.com

Anthony Ho
Anthony Ho
10,228 Points

After sending picture message to the users, Console log says "Retrieved 0 messages"

The code is exactly the same as the tutorial in the viewWillAppear method in InboxViewController

PFQuery *query = [PFQuery queryWithClassName:@"Messages"]; [query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]]; [query orderByDescending:@"createdAt"]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if(error){ NSLog(@"Error %@ %@", error, [error userInfo]); } else{ //we found messages self.messages = objects; [self.tableView reloadData]; NSLog (@"Retrieved %d messages", [self.messages count]);

Anthony Ho
Anthony Ho
10,228 Points

I asked this question before, but I didn't the right answers

6 Answers

Lee Hardy
Lee Hardy
5,407 Points

Hi Anthony,

In your code you use

[query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];

But on parse, you have spelled recipientIds with an s after recipient, yours reads recipientsIds on parse.

Change your code to use recipientsIds and it should work ok

Anthony Ho
Anthony Ho
10,228 Points

Thanks a lot, it finally worked

Lee Hardy
Lee Hardy
5,407 Points

No problem, glad to help

Have a look in the Parse website to see if the message exists.

Anthony Ho
Anthony Ho
10,228 Points

The messages are def there

Lee Hardy
Lee Hardy
5,407 Points

Sorry, misread the post last time.

I'd start by checking the spelling of objects etc, as your code above looks fine to me (checked against mine). Ensure your "Messages" class and the field names within the messages class are spelled correctly and use the correct case, as I believe parse is case-sensitive.

Another check is make sure that you're getting the current users objectID, put the below code after [query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];

NSLog(@"Current user ID: %@", [[PFUser currentUser] objectId]);

This will show the user objectID, make sure its there and then not blank. Once you have this user objectID, I'd log into parse and check that user objectID against the user you logged in with the make sure they match. Then, have a look in the Messages class on parse for the message you sent, and ensure that the user objectID you logged above is in the array of recipientIds of the message

Hope this helps

Anthony Ho
Anthony Ho
10,228 Points

Thanks. I tried it, but the "Current User ID" NSlog returns the senderId instead of the objectId.

Lee Hardy
Lee Hardy
5,407 Points

Have you tried sending the message to yourself? Then the senderID will be same as recipientID

Anthony Ho
Anthony Ho
10,228 Points

Yeh i did that too, but console still shows "retrieved 0 messages"

Inside Parse, do you have a column for the recipientIds and do the messages show the same ID as the currentUser?

Sai Kiran Dasika
PLUS
Sai Kiran Dasika
Courses Plus Student 7,278 Points

Hey man i think you should check your fields names what you have typed on parse because if the column names are wrong then the query will work but will not get any data back into the array. Please check that or else you can send me an email at feedback@burst.co.in