感谢这里的其他几个帖子,我已成功地使用Instagram iPhone挂钩打开Instagram,并通过我的应用成功地将照片呈现给它。
(我已将ViewController
课程设为delegate
UIDocumentInteractionController
,alloc/init
编辑nonatomic/retain property
UIDocumentInteractionController
..
但是,我放入文档控制器注释属性的NSDictionary
中的关键字似乎不会转移到Instagram上 - 标题区域只是空的.. 。
有没有人知道如何处理这个?
这是我的方法:
- (void) uploadImageToInstagram:(UIImage *)imageToUpload {
NSLog(@"postToInstagramInBackground");
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
// Upscale to 612x612
imageToUpload = [self upscaleImage:imageToUpload];
// Get JPG + IGO Format
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/generate.igo"];
[UIImageJPEGRepresentation(imageToUpload, 1.0) writeToFile:savePath atomically:YES];
// Paths
NSURL *imageURL = [NSURL fileURLWithPath:savePath];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@",savePath]];
// Setup DocController
self.docController.UTI = @"com.instagram.photo";
self.docController = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.docController.annotation = [NSDictionary dictionaryWithObject:@"MyApp" forKey:self.caption.text];
[self.docController setURL:imageURL];
[self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES ];
}
else {
NSLog(@"Instagram not installed in this device!\nTo share image please install Instagram.");
}
}
这里有一些我没有包含的方法,一个用于升级图像以确保其612x612,另一个用于设置文档控制器的文件URL。
谢谢你提前!
~Jesse
答案 0 :(得分:0)
正确的语法应该是
self.docController.annotation = [NSDictionary dictionaryWithObject:self.caption.text forKey:@"InstagramCaption"];