【发布时间】:2012-08-26 23:06:24
【问题描述】:
我有一张图片,我想将其导出到 Instagram,以便发布。
我使用的代码是:
NSURL *instagramURL = [NSURL URLWithString:@"instagram://location?id=1"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"Image.igo"];
UIImage *image = [UIImage imageNamed:@"01.png"];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
NSURL *imageUrl = [NSURL fileURLWithPath:savedImagePath];
NSLog(@"%@",imageUrl);
UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc] init];
docController.delegate = self;
docController.UTI = @"com.instagram.exclusivegram";
docController.URL = imageUrl;
//[docController setURL:imageUrl];
[docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
当我运行应用程序时,应用程序显示写有“Instagram”图标的按钮,但是当我触摸它时,按钮消失了,什么也没有发生。应用没有崩溃,但什么也没发生。
我在代码中遗漏了什么?
问候 布鲁诺
【问题讨论】:
-
你能更具体一点“什么都没发生”吗?当您调试它时,是否所有代码都执行而您只是看不到您的文档交互控制器?还是有其他东西不起作用?
-
Carl,所有代码都已执行,但没有任何反应...图像为 612 x 612 像素,NSLog 显示 URL:URL = file://localhost/var/mobile/Applications/96007767 -1D2E-4017-9EEA-072F3CE19452/Documents/Image.ig
-
尝试与
-presentOpenInMenuFromRect:inView:Animated:不同的第一个参数。也许试试发送按钮的框架? -
您尝试过UTI com.instagram.photo 和.ig 扩展名吗?是否调用了委托方法?
标签: objective-c ios cocoa-touch instagram