使用他们的iOS挂钩将照片发布到Instagram

时间:2012-01-30 09:44:44

标签: objective-c ios instagram

我在iOS应用程序中使用以下代码来使用Instagram iPhone挂钩将照片发布到Instagram。我只希望“Open In ...”菜单中有Instagram应用程序,没有其他应用程序。但在我的情况下,Camera +也出现了。我怎么能限制在Instagram上?

另外,我可以直接打开Instagram而不是显示Open In菜单吗?

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];
}

5 个答案:

答案 0 :(得分:12)

BTW Instagram为此添加了一个独占文件扩展名(ig)和UTI(com.instagram.exclusivegram)。它仍然打开Open with ...菜单,但唯一的选择是Instagram。

此处有更多信息:https://instagram.com/developer/mobile-sharing/iphone-hooks/

答案 1 :(得分:8)

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

  1. 使用.igo扩展名而不是.ig保存图片。这是文件类型的“独占”版本。

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

  3. 使用UIDocumentInteractionController

  4. 展示您的presentOpenInMenuFromRect:inView:animated

答案 2 :(得分: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];

答案 3 :(得分:0)

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

答案 4 :(得分:0)

self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];

self.documentInteractionController=[UIDocumentInteractionController  interactionControllerWithURL:imgurl];

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

以相同的顺序使用此代码。 这里documentInteractionController是UIDocumentInteractionController.just的对象,供您参考。 你只能在“打开”窗口中获得Instagram。

相关问题