我有一张图片,我想将它导出到 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”的按钮图标,但是当我触摸它时,该按钮消失了,并且没有任何反应。该应用程序没有崩溃,但什么也没有发生。
我的代码中遗漏了什么?
问候 布鲁诺
最佳答案
我想问题是您没有保留 UIDocumentInteractionController
。在你的类里面为它制作一个伊娃。
确保在委托(delegate)上调用方法 documentInteractionController:didEndSendingToApplication:
。
另请查看 Instagram 文档:http://instagram.com/developer/iphone-hooks/
When triggered, Instagram will immediately present the user with our filter screen. The image is preloaded and sized appropriately for Instagram. Other than using the appropriate image format, described above, our only requirement is that the image is at least 612px tall and/or wide. For best results, Instagram prefers opening a JPEG that is 612px by 612px square. If the image is larger, it will be resized dynamically.
要验证是否已安装 Instagram,请检查 URL instagram://app
。 URL instagram://location?id=LOCATION_ID
仅用于位置供稿!
关于objective-c - 将图像导出到 Instagram - iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12134630/