Skip to content

Instantly share code, notes, and snippets.

@mrsidique
Created April 5, 2012 17:24
Show Gist options
  • Select an option

  • Save mrsidique/2312671 to your computer and use it in GitHub Desktop.

Select an option

Save mrsidique/2312671 to your computer and use it in GitHub Desktop.
Get contacts
- (void)getContacts {
NSUserDefaults *zapData = [NSUserDefaults alloc];
double distance;
if ([[zapData objectForKey:@"distanceFilter"]isEqualToString:@"50 Yards"]) {
distance = 0.0284090909;
}
else if ([[zapData objectForKey:@"distanceFilter"]isEqualToString:@"100 Yards"]) {
distance = 0.0568181818;
}
else if ([[zapData objectForKey:@"distanceFilter"]isEqualToString:@"500 Yards"]) {
distance = 0.284090909;
}
else if ([[zapData objectForKey:@"distanceFilter"]isEqualToString:@"1 Mile"]) {
distance = 1;
}
else if ([[zapData objectForKey:@"distanceFilter"]isEqualToString:@"5 Miles"]) {
distance = 5;
}
else if ([[zapData objectForKey:@"distanceFilter"]isEqualToString:@"10 Miles"]) {
distance = 10;
}
else if ([[zapData objectForKey:@"distanceFilter"]isEqualToString:@"Infinity"]) {
distance = 25000;
}
else {
distance = 1;
}
if (point != NULL) {
//[SVProgressHUD showWithStatus:@"Loading Contacts"];
PFQuery *getUsers = [PFQuery queryWithClassName:@"cardLocation"];
// Interested in locations near user.
NSNumber *limit = [NSNumber numberWithInt:1000];
[getUsers setLimit:limit];
[getUsers whereKey:@"location" nearGeoPoint:point withinMiles:distance];
[getUsers whereKey:@"updatedAt" greaterThan:[NSDate dateWithTimeIntervalSinceNow:-1800]];
[getUsers findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"%d", objects.count);
resultSet = [[NSMutableArray alloc]initWithCapacity:1];
//NSLog(@"Successfully retrieved %d record.", objects.count);
for (PFObject *cardLocation in objects) {
PFObject *card = [cardLocation objectForKey:@"card"];
if ([[card objectForKey:@"broadcasting"]isEqualToString:@"1"] && [[card objectForKey:@"active"]isEqualToString:@"1"]) {
NSString *cardOwnerIdString = [[card objectForKey:@"cardOwner"] objectId];
//NSLog(@"Card Owner: %@", cardOwnerIdString);
NSString *currentUserIdString = [currentUser objectId];
//NSLog(@"Current User: %@", currentUserIdString);
if (![cardOwnerIdString isEqualToString:currentUserIdString]) {
//NSLog(@"%@", @"Not Current User!");
if (card != nil) {
[resultSet addObject:card];
}
}
}
}
[self setContentsList:resultSet];
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:0.0];
[resultTableView reloadData];
[SVProgressHUD dismiss];
}
else {
NSLog(@"%@", [error valueForKey:@"UserInfo"]);
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:0.0];
}
}];
}
else {
[SVProgressHUD dismiss];
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:0.0];
[self performSelector:@selector(setCardLocation) withObject:nil afterDelay:2.0];
if (nil == locationManager) {
locationManager = [[CLLocationManager alloc] init];
}
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// Set a movement threshold for new events.
locationManager.distanceFilter = 50;
[locationManager startUpdatingLocation];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment