2013-01-17 43 views
6

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

(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上。我錯過了什麼嗎?誰能幫我這個?

感謝

+0

同樣的問題在這裏。 :(如果你確實搞清楚了,請你可以跟我分享你所做的事情 –

+0

你們有沒有想過嗎? –

回答

0

首先,在你的代碼,你沒有的setupControllerWithURL: usingDelegate:返回值分配給一個對象,這樣的方法並不實際完成什麼,只是創造UIDocumentInteractionController的一個新實例,將其丟棄。

其次,從文檔:

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

你不保留文檔控制器(或者在ARC的情況下,分配給強引用的屬性)從我可以告訴。因爲在下一行igImageHookFile = [NSURL fileURLWithPath:jpgPath];你創建一個

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];是不必要的:

@property (nonatomic, strong) UIDocumentInteractionController *documentController; 

在你的@implementation: 在你@interface -

試試這個新實例並丟棄第一個實例。只需使用NSURL *igImageHookFile = [NSURL fileURLWithPath:jpgPath];

+0

我完成了這一切,但結果是相同的圖像不張貼在這,是否有可能它只在設備中工作不在模擬器中。我能做什麼??? – chakshu

+0

我試過[self.documentInteractionController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES]; 它的工作原理感謝daltonclaybrook .. :) – chakshu

+0

Can我知道這個圖像被成功分享給instagram?我只想在圖像共享成功時更新我的​​數據庫。 – Manthan