簡體   English   中英

圖像不會從ios 6發布在Instagram上

[英]Image not post on instagram from ios 6

我正在使用instagram-ios-sdk將Instagram集成到我的應用程序中。 我可以成功login Instagram並獲取訪問令牌,但在此之后,當我嘗試使用UIDocumentInteractionControllerUIImagePickerController發布圖片時,圖像不會發布。 發送圖片的代碼如下:

(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:的返回值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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM