Created
February 22, 2012 08:15
-
-
Save mrsidique/1883380 to your computer and use it in GitHub Desktop.
Getting other users within range
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
| for (NSUInteger i = 1; i < myZapCards.count; i++) { | |
| [cardsToQuery addObject:[myZapCards objectAtIndex:i]]; | |
| } | |
| PFQuery *getUsers = [PFQuery queryWithClassName:@"cardLocation"]; | |
| // Interested in locations near user. | |
| [getUsers whereKey:@"location" nearGeoPoint:point withinMiles:10]; | |
| [getUsers findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { | |
| if (!error) { | |
| resultSet = [[NSMutableArray alloc]initWithCapacity:1]; | |
| NSLog(@"Successfully retrieved %d record.", objects.count); | |
| for (PFObject *card in objects) { | |
| PFObject *cards = [card objectForKey:@"card"]; | |
| PFObject *currentUser = [[PFUser currentUser]objectForKey:@"username"]; | |
| PFObject *userID = [[[card objectForKey:@"card"] objectForKey:@"cardOwner"] objectForKey:@"username"]; | |
| NSString *currentUserNameString = [NSString stringWithFormat:@"%@", currentUser]; | |
| NSString *fetchedUserNameString = [NSString stringWithFormat:@"%@", userID]; | |
| if ([card objectForKey:@"card"] != nil) { | |
| //only get cards if they are currently set to broadcasting | |
| if ([[[card objectForKey:@"card"]objectForKey:@"active"]isEqualToString:@"1"]) { | |
| if ([[[card objectForKey:@"card"]objectForKey:@"broadcasting"]isEqualToString:@"1"]) { | |
| if (![currentUserNameString isEqualToString:fetchedUserNameString]) { | |
| NSTimeInterval timeSinceLastUpdate = [card.updatedAt timeIntervalSinceNow]; | |
| //only display users if they've checked in less than 30 minutes ago | |
| if (timeSinceLastUpdate > -1800) { | |
| [resultSet addObject:cards]; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment