Created
July 15, 2014 03:08
-
-
Save maml/11600341653c198a06c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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