Skip to content

Instantly share code, notes, and snippets.

@iggym
Forked from EchoAbstract/sharedPhotoStream.m
Created June 20, 2012 19:05
Show Gist options
  • Save iggym/2961601 to your computer and use it in GitHub Desktop.
Save iggym/2961601 to your computer and use it in GitHub Desktop.
Photo Stream
// In your view controller
// Make sure you have a class that stores image metadata
// For example, you could have your MyMetadata class with
// the following iVars:
// name -- The name of the image
// size -- The expected size of the image
// date -- The time the picture was taken
// location -- The place the image was taken
// peopleInPhoto -- An array of the 'id' attribute from KCSUsers
// in the picture
//
// When your imagePickerController:didFinishPickingMediaWithInfo: delegate
// gets called you should update the items in your metadata object.
// To save the current photo
- (void)sharePhoto: (UIImage *)image
withMetadata: (MyMetadata *)metadata
{
[KCSResourceService saveData:UIImagePNGRepresentation(image)
toResource:metadata.name
withDelegate:self];
}
// In your resource delegate
// This makes
- (void)resourceServiceDidCompleteWithResult:(KCSResourceResponse *)result
{
KCSCollection *metadataCollection = [[KCSClient sharedClient] collectionFromString:@"metadata"
withClass:[MyMetadata class]];
for (MyMetadata *metadata in self.imageMetadata){
if ([metadata.name isEqualToString:result.resourceId]){
[metadata saveToCollection:metadataCollection withDelegate:self];
}
}
}
// Later... when you want to actually display these images...
// perform a query against your metadata collection
// maybe to find a user or images within a certain Geo Area
// (see: http://docs.kinvey.com/ios-developers-guide.html#querying_data or
// http://docs.kinvey.com/ios-developers-guide.html#geoqueries for details)
// and in your delegate:
- (void)collection:(KCSCollection *)collection didCompleteWithResult:(NSArray *)result
{
// Get a path to the image cache
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"imageCache"];
// Loop through the returned metadata
for (MyMetadata *metadata in result){
// Download each photo to a local copy, your delegate method should
// handle the display logic
[KCSResourceService downloadResource:metadata.name
toFile:[dataPath stringByAppendingPathComponent: metadata.name]
withResourceDelegate:self];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment