2012-09-11 37 views
2

我无法使用ios App在Instagram上发布我的照片。我从stackoverflow的帖子中得到了下面的代码,但它不起作用。当Instagram启动时,它显示错误无法打开文件。请帮助我。无法在iOS应用中集成Instagram

NSURL *instagramURL = [NSURL URLWithString:@"instagram://location?id=1"]; 
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { 

     NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
     NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"Image.ig"]; 
     NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"Icon.png"]); 
     [imageData writeToFile:savedImagePath atomically:YES]; 
     NSURL *imageUrl = [NSURL fileURLWithPath:savedImagePath]; 
     docController = [[UIDocumentInteractionController alloc] init]; 
     docController.delegate = self; 
     [docController retain]; 
     docController.UTI = @"com.instagram.photo"; 
     [docController setURL:imageUrl]; 
     [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; 
    }else{ 

     UIAlertView *errorToShare = [[UIAlertView alloc] initWithTitle:@"Instagram unavailable " message:@"You need to install Instagram in your device in order to share this image" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [errorToShare show]; 
     [errorToShare release]; 
    } 
+0

我刚刚用612x612 jpeg图片测试过它,它工作正常。它不适用于PNG或更小的分辨率 – kashif789us

回答

2

instagram的最低分辨率为612x612。总是JPG。

0

完成起见,最小分辨率保持在612x612(这是由于显示视网膜上的图像的设备),但现在的Instagram支持JPEGPNG图像。发送到Instagram的所有非正方形图像必须在发布前裁剪。