Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Created September 14, 2012 20:23
Show Gist options
  • Save ChrisRisner/3724507 to your computer and use it in GitHub Desktop.
Save ChrisRisner/3724507 to your computer and use it in GitHub Desktop.
GeoDemo-ios4
- (IBAction)tapPostPOI:(id)sender {
UIImage *image = imageView.image;
NSData *data = UIImagePNGRepresentation(image);
//Just pass the call over to our generic serviceCaller
[serviceCaller postToUrl:sasURL
withBody:data andPostType:@"PUT" andContentType:@"image/jpeg" withCallback:^(NSString *response) {
//This is the callback code that the ServiceCaller will call upon success
labelSasUrl.text = response;
if ([response isEqualToString:@""])
labelSasUrl.text = @"Should have been a success, proceeding";
// Now add the location information to the server
NSString *poiURL = [[sasURL componentsSeparatedByString:@"?"] objectAtIndex:0];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
//build an info object and convert to json
NSDictionary* jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"My Image", @"Description",
[self generateUuidString], @"Id",
[prefs stringForKey:@"Latitude"], @"Latitude",
[prefs stringForKey:@"Longitude"], @"Longitude",
@"1", @"Type",
poiURL, @"Url",
nil];
NSError *error;
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary
options:NSJSONWritingPrettyPrinted error:&error];
//Pass the call over to our generic serviceCaller
[serviceCaller postToUrl:kAddPOIUrl
withBody:jsonData andPostType:@"POST" andContentType:@"application/json" withCallback:^(NSString *response) {
//This is the callback code that the ServiceCaller will call upon success
labelSasUrl.text = response;
if ([response isEqualToString:@""])
labelSasUrl.text = @"Should have been a success, poi added";
[self.navigationController popViewControllerAnimated:YES];
}];
}];
}
- (NSString *)generateUuidString
{
// create a new UUID
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
// create a new CFStringRef (toll-free bridged to NSString)
NSString *uuidString = (__bridge NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
// release the UUID
CFRelease(uuid);
return uuidString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment