objective-c - 将图像导出到 Instagram - iPhone

标签 objective-c ios cocoa-touch instagram

我有一张图片,我想将它导出到 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/

相关文章:

objective-c - 请求 ASIHTTPRequest 或 AFNetworking 时在队列中添加操作

iphone - 持久化 MPMediaItemCollection 对象的方法? (选自 iPod)

ios - 在运行 App 时编辑单元格时更新数组

iphone - 如何获取适用于 Xcode 3.2 的 iPhone SDK 2.2.1?

iphone - 现在 "English"或 "en"是首选 .lproj 文件夹名称吗?

objective-c - 当点击 'Next' 时移动到下一个 UITextField

iOS静态库编译错误-目录为空

ios - NSPredicate with block - 它是如何工作的

ios - 需要将 firebase 匿名帐户链接到 firebase 上的 google 登录或 facebook 登录帐户

iphone - 如何用Cocos2d-iPhone画线