iphone - 图片无法从 iOS 6 发布到 Instagram

标签 iphone ios instagram

我正在使用 instagram-ios-sdk 将 Instagram 集成到我的应用程序中。我可以成功 login 到 Instagram 并获得访问 token ,但是之后当我尝试使用 UIImagePickerController 中的 UIDocumentInteractionController 发布图片时,图片未发布。发送图片的代码如下:

(void)_startUpload:(UIImage *) image {
    NSLog(@"Image Object = %@",NSStringFromCGSize(image.size));
    NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.igo"];
    [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
    NSLog(@"file url  %@",jpgPath);

    NSURL *igImageHookFile = [[NSURL alloc] init];
igImageHookFile = [NSURL fileURLWithPath:jpgPath];
NSLog(@"File Url = %@",igImageHookFile);

    documentInteractionController.UTI = @"com.instagram.photo";
    [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
    [self setupControllerWithURL:igImageHookFile usingDelegate:self];

    [documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}

(UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL  usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
    NSLog(@"%@",fileURL);
    UIDocumentInteractionController *interactionController =
        [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;

    return interactionController;
}

我把图片转成了.ig格式,分辨率为(612 *612)。但是图片仍然没有发布到 Instagram 上。我错过了什么吗?谁能帮我解决这个问题?

谢谢

最佳答案

首先,在您的代码中,您没有将 setupControllerWithURL: usingDelegate: 的返回值分配给一个对象,因此该方法实际上并没有完成任何事情,只是创建了一个新的实例UIDocumentInteractionController 并丢弃它。

其次,来自文档:

"Note that the caller of this method needs to retain the returned object."

据我所知,您没有保留文档 Controller (或在 ARC 的情况下将其分配给强引用属性)。

试试这个 - 在你的@interface 中:

@property (nonatomic, strong) UIDocumentInteractionController *documentController;

在你的@实现中:

self.documentController = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.documentController.delegate = self;
self.documentController.UTI = @"com.instagram.photo";
[self.documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

另外,NSURL *igImageHookFile = [[NSURL alloc] init]; 行是不必要的,因为在下一行 igImageHookFile = [NSURL fileURLWithPath:jpgPath]; 你'正在创建一个新实例并丢弃第一个实例。只需使用 NSURL *igImageHookFile = [NSURL fileURLWithPath:jpgPath];

关于iphone - 图片无法从 iOS 6 发布到 Instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14372137/

相关文章:

iphone - UItableview 不会滚动第一行我想使用类似标题并且我已经有部分标题

iphone - CGContextDrawImage 在 iPhone 4 上非常慢

iphone - sqlite3 更新在 ios 中不起作用

ios - 按应用程序图标后的上下文菜单

iphone - 检测 iPod 库是否使用 iTunes Match

ios - UILabels 和自定义 UITableView 单元格

ios - NSUser Defaults - 将 3 个变量保存在一起然后获取

javascript - Instagram 链接打开应用程序内浏览器而不是外部/ native 浏览器

node.js - 如何使 Instagram OAuth(或任何 OAuth)始终强制用户登录,即使他们已登录应用程序的网站?

android - 在 Android 中向 gridview 添加页眉和页脚