【问题标题】:Export image to Instagram - iPhone将图像导出到 Instagram - iPhone
【发布时间】: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


【解决方案1】:

我猜问题是你没有保留UIDocumentInteractionController。在你的课堂上为它创建一个 ivar。

确保在委托上调用方法 documentInteractionController:didEndSendingToApplication:

还可以查看 Instagram 文档:http://instagram.com/developer/iphone-hooks/

触发后,Instagram 将立即向用户展示我们的 过滤屏幕。图像已预加载并适当调整大小 Instagram。除了使用适当的图像格式,描述 上面,我们唯一的要求是图像至少 612px 高 和/或宽。为获得最佳效果,Instagram 更喜欢打开 JPEG 是 612 像素 x 612 像素的正方形。如果图像较大,它将调整大小 动态的。

要验证是否安装了 Instagram,请检查 URL instagram://app。 URL instagram://location?id=LOCATION_ID 仅用于位置供稿!

【讨论】:

  • Phix23 成功了!非常感谢 !!!我会在这里发帖以帮助任何有同样问题的人。 --------------------------------------------------在 .h 添加 @property (nonatomic, retain) UIDocumentInteractionController *docController; --------------------------------------------------
  • 感谢 Phix23 和 Brunohdc .....我正在使用 ARC ..它不允许我放置 [docController retain];我能做什么..但是如果我将 -fno-objc-arc 放在编译器标志中,它工作正常..但我想在 ARC 中使用它..请帮助我..提前谢谢...
  • @AshokKumarIOS 与 ARC 只是为 docController 创建一个 ivar 或 strong 属性。并删除retain
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-15
  • 1970-01-01
  • 1970-01-01
  • 2013-07-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多