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 trialNic Huang
Courses Plus Student 10,573 PointsRibbit with push notification
I try to take Ribbit further and add more features to it. I can now successfully send push notification (server - to client) from my Parse console. Devices can receive it. However, my client-to-client push has some issues. When I'm sending a photo to one of my friends, I'm sending notification as well. The notification is sent successful, but none of devices receive it. Parse console always shows 0 recipients and subscribers. I don't understand why. Hope someone with the experience can give me some help. Thanks in advance.
The below are my client to client push code. I think I have everything ready, but devices still can't receive it......
// set PFInstallation in appDelegate
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setObject:[PFUser currentUser] forKey:@"owner"];
[currentInstallation saveInBackground];
// handle recipient push after sending message
NSArray *megRecipients = [message objectForKey:@"recipientIds"];
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"owner" containedIn:megRecipients];
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
[push setMessage:[NSString stringWithFormat: @"%@ send you a new message", [PFUser currentUser].username ]];
[push sendPushInBackground];
4 Answers
Ben Jakuben
Treehouse TeacherGreat discussion in here! I missed this one but am so glad you all got it working. Paul Dunahoo, I might turn this into an add-on workshop because this is really cool and would complement the course nicely.
jschlansky
7,229 PointsI came here to ask the exact same thing. I have been working on adding push notifications successfully with Parse for the past 4 hours, and I am at the exact same stage as you.
I'll keep working on it and update if I have anything new.
EDIT: Are you testing with multiple devices? I think that you might not be able to send a push notification to a user account that is not currently signed into the app. I have not tested this on multiple devices, but will do so and check back.
I also created a post on the Parse forums: https://parse.com/questions/sending-a-push-notification-from-one-user-to-another-user
And I just posted on StackOverflow: http://stackoverflow.com/questions/20626513/sending-a-push-notification-from-one-user-to-another-user-with-parse
Some links that are leading me on the right track:
https://parse.com/docs/ios/api/Classes/PFPush.html
https://parse.com/questions/sending-push-notifications-to-a-specific-user
Nic Huang
Courses Plus Student 10,573 PointsHey Taylor,
I know what's wrong with our target push. When We are setting value to owner, we should use "[PFUser currentUser].objectId", instead of [PFUser currentUser]. The latter gives you a pointer to user, but we need a string to set Push query.
my Target push now works successfully, and Yes , I'm testing with multiple devices. I also left the answer to your question on StackOverflow. Please give me a thumb-up if it works. I'm new to StackOverflow :)
[currentInstallation setObject:[PFUser currentUser].objectId forKey:@"owner"];
jschlansky
7,229 PointsHey Nic, Thanks.
Do you mean changing this:
[currentInstallation setObject:[PFUser currentUser] forKey:@"owner"];
to this:
[currentInstallation setObject:[PFUser currentUser].objectId forKey:@"owner"];
I tried that and I get an error like this: Error: invalid type for key owner, expected *_User, but got string
This means that a string is not a valid object to use in the "setObject:" method.
Can you help me out by explaining your solution in a bit more detail? Thanks.
Nic Huang
Courses Plus Student 10,573 PointsYou have that error because you trying to assign a string into a non-string column "owner";
You can drop the "owner" column in parse and created another column like "userId", and most importantly, give it a string type. And make sure your device save PFInstallation with new userId string.
jschlansky
7,229 PointsThanks Nic. I think I have it working now. I really appreciate it!
Paul Dunahoo
5,390 PointsToo bad it isn't part of the course.
Nicolaus Nsarray
Courses Plus Student 65 PointsDid you get it to work. Please post code. Karma is watching the webb.
jschlansky
7,229 PointsYep. Nic Huang figured it out. There is a bunch of code and explanations over at:
jschlansky
7,229 Pointsjschlansky
7,229 PointsThis is a really great idea. Is there a way for students to submit video tutorials that might complement courses like this?
Alberto Huerdo
2,650 PointsAlberto Huerdo
2,650 PointsHi Ben, di you had time to work on this?