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 trialAnthony Ho
10,228 PointsAfter 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]);
6 Answers
Lee Hardy
5,407 PointsHi 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
10,228 PointsThanks a lot, it finally worked
Lee Hardy
5,407 PointsNo problem, glad to help
Steve Hunter
57,712 PointsHave a look in the Parse website to see if the message exists.
Anthony Ho
10,228 PointsThe messages are def there
Lee Hardy
5,407 PointsSorry, 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
10,228 PointsThanks. I tried it, but the "Current User ID" NSlog returns the senderId instead of the objectId.
Lee Hardy
5,407 PointsHave you tried sending the message to yourself? Then the senderID will be same as recipientID
Anthony Ho
10,228 PointsYeh i did that too, but console still shows "retrieved 0 messages"
Steve Hunter
57,712 PointsInside Parse, do you have a column for the recipientIds
and do the messages show the same ID as the currentUser
?
Sai Kiran Dasika
Courses Plus Student 7,278 PointsHey 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
Anthony Ho
10,228 PointsAnthony Ho
10,228 PointsI asked this question before, but I didn't the right answers