2012-08-26 31 views
4

我有一個圖像,我想將它導出到Instagram,所以我可以發佈它。將圖像導出到Instagram - iPhone

我正在使用的代碼是:

NSURL *instagramURL = [NSURL URLWithString:@"instagram://location?id=1"]; 
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { 
    NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"Image.igo"]; 

    UIImage *image = [UIImage imageNamed:@"01.png"]; 

    NSData *imageData = UIImagePNGRepresentation(image); 
    [imageData writeToFile:savedImagePath atomically:YES];   
    NSURL *imageUrl = [NSURL fileURLWithPath:savedImagePath]; 
    NSLog(@"%@",imageUrl); 
    UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc] init];   
    docController.delegate = self; 
    docController.UTI = @"com.instagram.exclusivegram"; 
    docController.URL = imageUrl; 
    //[docController setURL:imageUrl]; 
    [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; 
} 

當我運行應用程序,在App展示寫有「Instagram的」圖標按鈕,但是當我觸摸它,按鈕消失,並沒有任何反應。該應用程序沒有崩潰,但沒有發生。

我在代碼中錯過了什麼?

問候 布魯諾

+0

你能更具體一點嗎?當您調試它時,是否執行所有代碼,並且只是看不到您的文檔交互控制器?還是別的東西沒有用? –

+0

卡爾,所有的代碼被執行,什麼都沒有發生...... 圖像是612 x 612像素,NSLog顯示URL: URL = file:// localhost/var/mobile/Applications/96007767-1D2E-4017 -9EEA-072F3CE19452/Documents/Image.ig – Brunohdc

+0

爲'-presentOpenInMenuFromRect:inView:Animated:'嘗試不同的第一個參數。也許嘗試發送按鈕的框架? –

回答

3

我想這個問題是你不保留UIDocumentInteractionController。在你的班級爲它做一個伊娃。

確保在委託上調用方法documentInteractionController:didEndSendingToApplication:

還檢查了Instagram的文檔:http://instagram.com/developer/iphone-hooks/

觸發後,Instagram的會立即與我們 濾網展示給用戶。該圖像預加載並適用於Instagram的 。除了使用上面描述的 描述的合適的圖像格式之外,我們唯一的要求是圖像至少爲612px高和/或寬。爲了獲得最佳效果,Instagram傾向於打開一個JPEG,即 是612px乘以612px的正方形。如果圖片較大,則會動態調整 的大小。

要驗證是否安裝了Instagram,請檢查URL instagram://app。 URL instagram://location?id=LOCATION_ID僅適用於位置Feed!

+1

Phix23它的工作! 非常感謝! 我會在這裏發帖以幫助任何有同樣問題的人。 ------------------------------------------------- - in .h add @property(nonatomic,retain)UIDocumentInteractionController * docController; ------------------------------------------------- - – Brunohdc

+0

感謝Phix23和Brunohdc .....我使用ARC ..它不允許我把[docController保留];我能做些什麼..但是,如果我把-fno-objc-arc放在編譯器標誌中,它工作正常..但我想在ARC中使用它..請幫助我..在高級...感謝... –

+1

@AshokKumarIOS使用ARC只需爲docController創建一個ivar或strong屬性。並放下'保留'。 – Felix