Created
February 22, 2012 08:11
-
-
Save mrsidique/1883371 to your computer and use it in GitHub Desktop.
Send a zap card
This file contains hidden or 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
| PFObject *recipient; | |
| recipient = [selectedRecipient objectForKey:@"cardOwner"]; | |
| //send card to recipient | |
| PFQuery *checkExisting = [PFQuery queryWithClassName:@"exchangedCards"]; | |
| [checkExisting whereKey:@"cardRecipient" equalTo:recipient]; | |
| [checkExisting whereKey:@"zapCard" equalTo:selectedCardToSend]; | |
| [checkExisting findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { | |
| if (objects.count == 0) { | |
| //send your card to person | |
| PFObject *exchangeCard = [PFObject objectWithClassName:@"exchangedCards"]; | |
| [exchangeCard setObject:[PFUser currentUser] forKey:@"user"]; | |
| [exchangeCard setObject:recipient forKey:@"cardRecipient"]; | |
| [exchangeCard setObject:selectedCardToSend forKey:@"zapCard"]; | |
| [exchangeCard setObject:@"0" forKey:@"cardAccepted"]; | |
| if (point) { | |
| [exchangeCard setObject:point forKey:@"locationExchanged"]; | |
| } | |
| [exchangeCard saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { | |
| if (!error) { | |
| [PFPush sendPushMessageToChannelInBackground:[recipient objectId] | |
| withMessage:[NSString stringWithFormat:@"%@ %@", [selectedCardToSend objectForKey:@"name"], @"would like to send you a ZAP card"]]; | |
| UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Zap Card Sent" message:@"Zap Card has been sent to the selected user" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| } | |
| else { | |
| UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:[[error userInfo] objectForKey:@"error"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| } | |
| }]; | |
| } | |
| else { | |
| UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"This user already has the Zap Card which you are trying to send" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| } | |
| }]; | |
| //get recipient's card | |
| //check if the user already has this card | |
| PFQuery *crossCheckExisting = [PFQuery queryWithClassName:@"exchangedCards"]; | |
| [crossCheckExisting whereKey:@"cardRecipient" equalTo:[PFUser currentUser]]; | |
| [crossCheckExisting whereKey:@"zapCard" equalTo:selectedRecipient]; | |
| [crossCheckExisting findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { | |
| if (objects.count == 0) { | |
| //Get person's card | |
| PFObject *exchangeCard = [PFObject objectWithClassName:@"exchangedCards"]; | |
| [exchangeCard setObject:[PFUser currentUser] forKey:@"cardRecipient"]; | |
| [exchangeCard setObject:recipient forKey:@"user"]; | |
| [exchangeCard setObject:selectedRecipient forKey:@"zapCard"]; | |
| [exchangeCard setObject:@"1" forKey:@"cardAccepted"]; | |
| if (point) { | |
| [exchangeCard setObject:point forKey:@"locationExchanged"]; | |
| } | |
| [exchangeCard saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { | |
| if (!error) { | |
| } | |
| else { | |
| UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:[[error userInfo] objectForKey:@"error"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; | |
| [alert show]; | |
| } | |
| }]; | |
| } | |
| }]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment