我有一個圖像,我想將它導出到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的」圖標按鈕,但是當我觸摸它,按鈕消失,並沒有任何反應。該應用程序沒有崩潰,但沒有發生。
我在代碼中錯過了什麼?
問候 布魯諾
你能更具體一點嗎?當您調試它時,是否執行所有代碼,並且只是看不到您的文檔交互控制器?還是別的東西沒有用? –
卡爾,所有的代碼被執行,什麼都沒有發生...... 圖像是612 x 612像素,NSLog顯示URL: URL = file:// localhost/var/mobile/Applications/96007767-1D2E-4017 -9EEA-072F3CE19452/Documents/Image.ig – Brunohdc
爲'-presentOpenInMenuFromRect:inView:Animated:'嘗試不同的第一個參數。也許嘗試發送按鈕的框架? –