【问题标题】:Post photo to Instagram using their iOS hooks使用他们的 iOS 挂钩将照片发布到 Instagram
【发布时间】:2012-01-30 09:44:43
【问题描述】:

我在我的 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];
}

【问题讨论】:

  • 你能告诉我什么是 self.exportBarButtonItem 以及它会做什么我也在尝试整合它......
  • 嘿,你这样做了吗?我也需要你的帮助
  • @amaltasCoder 你这样做了吗?请分享它的代码。上面的代码没有像我一样工作。
  • 你们找到解决办法了吗?
  • 只是添加到 cmets - 如果找到解决方案,请发布 - 谢谢!

标签: objective-c ios instagram


【解决方案1】:

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

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

【讨论】:

  • 我已经尝试过这个 UTI(com.instagram.exclusivegram) 但它仍然显示我设备上安装的其他应用程序处于打开状态...还有其他出路吗?
  • 其他应用程序被 ig 扩展所吸引。尝试使用 igo 扩展名保存您的图像文件并使用 UTI。如果您仍然遇到问题,可以发布一些代码吗?
  • ^ 您是如何解决问题的?我正在使用 igo 扩展程序,但其他应用程序现在也可以使用它。
  • @Manthan,请告诉我们好吗?
  • @pallzoltan 你可以在这个链接上查看我的回答stackoverflow.com/questions/16954810/…
【解决方案2】:

你可以从这个link得到解决方案。

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

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

  3. 通过presentOpenInMenuFromRect:inView:animated 展示您的UIDocumentInteractionController

【讨论】:

  • presentOpenInMenuFromRect:inView:animated 别忘了使用这个方法。 D:
【解决方案3】:

这对我有用,像这样做,你将只有 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];

【讨论】:

  • 干得好!解决问题。
【解决方案4】:

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

【讨论】:

  • 这已经过时了,请参阅@JoshOiknine answer。另外,第二个问题是 IMO 最有趣的问题。
【解决方案5】:
self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];

self.documentInteractionController=[UIDocumentInteractionController  interactionControllerWithURL:imgurl];

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

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

【讨论】:

  • 您的第二行正在覆盖您在第一行中设置的值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-30
相关资源
最近更新 更多