Skip to content

Instantly share code, notes, and snippets.

@bryanjclark
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanjclark/9372802 to your computer and use it in GitHub Desktop.
Save bryanjclark/9372802 to your computer and use it in GitHub Desktop.
Embedding a photos.app.net object in a new ANKPost (ADNKit on iOS)
UIImage *imageToUpload = ...
ANKPost *post = [ANKPost new];
post.text = @"Hello, world. Here's a photo of you:";
post.entities = [ANKEntities new];
post.entities.parseLinks = YES;
post.entities.parseMarkdownLinks = YES;
//Upload the file
NSData *imageData = UIImageJPEGRepresentation(image, 1.0f);
ANKFile *file = [ANKFile new];
file.kind = @"com.myCompany.myApp.image";
file.type = @"net.core.app.oembed";
file.mimeType = @"image/jpeg";
file.name = @"Image from Your App";
file.isPublic = isPublic;
[[ANKClient currentClient] createFile:file withData:imageData completion:^(id responseObject, ANKAPIResponseMeta *meta, NSError *error) {
if (error) {
NSLog(@"Error creating image: %@", error);
} else {
ANKFile *file = (ANKFile *)responseObject;
ANKAnnotation *annotation = [ANKAnnotation oembedAnnotationForFile:file];
post.annotations = @[annotation];
[post.text stringByAppendingString:[ANKLinkEntity photoLinkEntityForPost]];
[[ANKClient currentClient] createPost:post completion:^(id responseObject, ANKAPIResponseMeta *meta, NSError *error) {
if (error) {
NSLog(@"Error creating post: %@", error);
} else {
NSLog(@"Posted!");
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
}];
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment