12

我在我的 iOS 应用程序中使用以下代码来使用 Instagram iPhone 挂钩将照片发布到 Instagram。我只希望“打开方式...”菜单有 Instagram 应用程序,没有其他应用程序。但就我而言,Camera+ 也出现了。如何限制 Instagram?

另外,我可以直接打开 Instagram 而不是显示“打开方式”菜单吗?

NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    //imageToUpload is a file path with .ig file extension
    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:imageToUpload]];
    self.documentInteractionController.UTI = @"com.instagram.photo";
    self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"my caption" forKey:@"InstagramCaption"];
    [self.documentInteractionController presentOpenInMenuFromBarButtonItem:self.exportBarButtonItem animated:YES];
}
4

5 回答 5

12

顺便说一句,Instagram 为此添加了专有文件扩展名 (ig) 和 UTI (com.instagram.exclusivegram)。它仍然会打开 Open with... 菜单,但唯一的选项是 Instagram。

更多信息在这里:https ://instagram.com/developer/mobile-sharing/iphone-hooks/

于 2012-03-22T03:07:24.530 回答
8

您可以从此链接获得解决方案。

  1. 使用.igo扩展名而不是.ig. 这是文件类型的“专有”版本。

  2. 创建一个UIDocumentInteractionController,然后将值分配com.instagram.exclusivegram给该属性UTI

  3. 用. UIDocumentInteractionController_presentOpenInMenuFromRect:inView:animated

于 2013-02-26T07:48:28.043 回答
4

这对我有用,像这样做,你将只有 Instagram 作为打开图像的唯一应用程序。

    NSString *documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    // *.igo is exclusive to instagram
    NSString *saveImagePath = [documentDirectory stringByAppendingPathComponent:@"Image.igo"];
    NSData *imageData = UIImagePNGRepresentation(filteredImage);
    [imageData writeToFile:saveImagePath atomically:YES];

    NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];

    _docController=[[UIDocumentInteractionController alloc]init];
    _docController.delegate=self;
    _docController.UTI=@"com.instagram.photo";
    [_docController setURL:imageURL];
    _docController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:@"#yourHashTagGoesHere",@"InstagramCaption", nil];
    [_docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
于 2014-09-05T22:22:06.740 回答
0
self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];

self.documentInteractionController=[UIDocumentInteractionController  interactionControllerWithURL:imgurl];

self.documentInteractionController.UTI = @"com.instagram.exclusivegram";

以相同的顺序使用此代码。这里 documentInteractionController 是 UIDocumentInteractionController 的对象。仅供您了解。您只会在“打开方式”窗口中获得 Instagram。

于 2013-06-18T07:38:42.250 回答
0

仅回答您的第一个问题:您可能可以将“在...中打开”菜单限制为仅显示您设备的 Instagram(例如,通过删除 Camera+ 应用程序),但您将无法限制将您的应用安装到其设备上的用户。那是因为 iPhone 能够识别哪些应用程序能够打开特定类型的文件,并且它会自动显示每个可以打开的文件。

于 2012-01-30T10:00:18.043 回答