图像不会从ios 6发布在Instagram上

cha*_*shu 6 iphone ios instagram

我正在使用Instagram将Instagram集成到我的应用程序中instagram-ios-sdk.我可以成功login访问Instagram并获得访问令牌,但在此之后,当我尝试使用UIDocumentInteractionControllerfrom 发布图片时UIImagePickerController,图片不会发布.发送图片的代码如下:

(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;
}
Run Code Online (Sandbox Code Playgroud)

我将图像转换为.ig格式,分辨率为(612*612).但是图像仍未发布Instagram.我错过了什么吗?谁能帮我这个?

谢谢

dal*_*ook 0

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

其次,从文档来看:

"Note that the caller of this method needs to retain the returned object."
Run Code Online (Sandbox Code Playgroud)

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

试试这个 - 在你的@界面中:

@property (nonatomic, strong) UIDocumentInteractionController *documentController;
Run Code Online (Sandbox Code Playgroud)

在你的@implementation中:

self.documentController = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.documentController.delegate = self;
self.documentController.UTI = @"com.instagram.photo";
[self.documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
Run Code Online (Sandbox Code Playgroud)

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