UIDocumentInteractionController通过Instagram分享(仅限Instagram)

时间:2014-11-09 21:06:38

标签: ios objective-c instagram uidocument uti

当我使用UIDocumentInteractionController允许用户通过Instagram分享时,它确实有效,它会显示"打开"和" Instagram"作为其中一个选项...问题是它还会显示许多其他应用程序,例如" Facebook"和" Twitter" ...


我有什么方法可以让它只在Instagram应用程序中打开?

<小时/> Instagram声称有一种方法可以做到这一点:http://instagram.com/developer/iphone-hooks/但他们提到了这一点:
"Alternatively, if you want to show only Instagram in the application list (instead of Instagram plus any other public/jpeg-conforming apps) you can specify the extension class igo, which is of type com.instagram.exclusivegram."

但老实说我不清楚这一部分是什么意思,&#34; extension class igo&#34;


我的代码:

UIImage *imageToUse = [UIImage imageNamed:@"imageToShare.png"];
NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.ig"];
NSData *imageData=UIImagePNGRepresentation(imageToUse);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
docController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
docController.delegate = self;
docController.annotation = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"This is the users caption that will be displayed in Instagram"], @"InstagramCaption", nil];
docController.UTI = @"com.instagram.exclusivegram";
[docController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:self.view animated:YES];

2 个答案:

答案 0 :(得分:11)

原来让doc控制器只在Instagram中打开你只需保存你的png或jpg文件格式&#34; .igo&#34;文件类型扩展名,(也许代表Instagram-Only?)



改变了我的代码中的第三行代码来改为:

NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.igo"];

(&#34; igo&#34;)



然后它奏效了! :)

答案 1 :(得分:4)

iOS 13的较低版本:

NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.igo"];

在iOS 13之后:

NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.ig"];