Last active
August 29, 2015 13:57
-
-
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)
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
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