Skip to content

Instantly share code, notes, and snippets.

@maml
Created July 15, 2014 03:08
Show Gist options
  • Save maml/11600341653c198a06c7 to your computer and use it in GitHub Desktop.
Save maml/11600341653c198a06c7 to your computer and use it in GitHub Desktop.
+ (void)blurbWasLiked:(PFObject *)blurb byUser:(PFUser *)liker
{
/*
Query for blurb's user
*/
PFQuery *userQuery=[PFUser query];
PFUser *blurbUser = [blurb objectForKey:@"user"];
[userQuery whereKey:@"objectId" equalTo:blurbUser.objectId];
/*
Send push to notification to the blurb's user
First stab it this just finds installation that matches the blurb's user but, the
blurb's user could have multiple devices, so we should find all installations that
match the blurb's user.
*/
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"user" matchesQuery:userQuery];
__block PFPush *push = [PFPush new];
[push setQuery:pushQuery];
PMKPromise *p = [TINParseRead unreadNotificationsCountForUser:[blurb objectForKey:@"user"]];
p.then(^(NSNumber *count){
NSString *countStr = [NSString stringWithFormat:@"%@", count];
NSString *message = [NSString stringWithFormat:@"@%@ liked your blurb, \"%@\"", liker.username, [blurb objectForKey:@"title"]];
[push setData: @{
@"alert":message,
@"sound":@"push-notification.aiff",
@"badge":countStr
}];
NSError *pushError;
[push sendPush:&pushError];
}).catch(^(NSError *error){
NSLog(@"%@", error.localizedDescription);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment