6

我正在使用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;
}

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

谢谢

4

1 回答 1

0

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

其次,从文档中:

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

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

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

@property (nonatomic, strong) UIDocumentInteractionController *documentController;

在您的@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];

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

于 2013-04-02T22:19:50.183 回答