我有一张图片,想要将其导出到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”的按钮及其图标,但当我点击它时,按钮消失了,什么都没有发生。应用程序没有崩溃,但是什么也没发生。
我在代码中错过了什么?
谢谢 Bruno
-presentOpenInMenuFromRect:inView:Animated:
的第一个参数。或许可以尝试发送按钮的框架? - Carl Veazey