【问题标题】:Post to instagram directly with Document Interaction Controller使用文档交互控制器直接发布到 Instagram
【发布时间】:2014-03-03 15:01:41
【问题描述】:

在我的应用程序中,我设法通过文档交互控制器将图像发布到 Instagram。这一个还显示了在 Dropbox、whatsapp 等上共享的选项。我不想要这些功能,我只想要 Instagram。有没有办法以编程方式单击 Instagram 按钮,或删除其他不需要的应用程序的按钮? 提前感谢您的回答。

编辑:这是代码,其中包含“com.instagram.exclusivegram”的行我设法只显示了 Instagram、Bump 和 Dropbox。我怎样才能让最后两个消失?

-(void)ShareInstagram
{

    [self storeimage];
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
    {

        CGRect rect = CGRectMake(0 ,0 , 612, 612);
        NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/15717.igo"];

        NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
        _dic.UTI = @"com.instagram.exclusivegram";
        _dic.delegate=self;
        _dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
        _dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
        _dic.delegate=self;
        [_dic presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];

        //  [[UIApplication sharedApplication] openURL:instagramURL];
    }
    else
    {
        //   NSLog(@"instagramImageShare");
        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.tag=3010;
        [errorToShare show];
    }
}


- (void) storeimage
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"15717.igo"];
    UIImage *NewImg=[self resizedImage:_imageToTweet inImage:CGRectMake(0, 0, 612, 612) ];
    NSData *imageData = UIImagePNGRepresentation(NewImg);
    [imageData writeToFile:savedImagePath atomically:NO];
}


- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate
{
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
    interactionController.delegate = self;

    return interactionController;
}

【问题讨论】:

  • 使用UIDocumentInteractionController 的全部意义在于让用户决定要做什么。如果您只想要 Instragram,请使用不同的解决方案。在这里做一些搜索。有很多关于直接发布到 Instagram 的现有主题。
  • 我没有找到任何关于直接发布的信息。你能帮我一些链接吗?谢谢。
  • @charles,你有没有找到只显示 Instagram 的解决方案?
  • @rmaddy 除了使用UIDocumentInteractionController,别无他法,别再误导人了。

标签: ios instagram uidocumentinteraction


【解决方案1】:

setupControllerWithURL:usingDelegate 方法会覆盖上面设置的_dic 实例变量的属性。

这些行无效:

_dic.UTI = @"com.instagram.exclusivegram";
_dic.delegate=self;

先实例化UIDocumentInteractionController,然后设置其属性:

NSURL *igImageHookFile = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@", jpgPath]];
_dic = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
_dic.UTI = @"com.instagram.exclusivegram";
_dic.delegate = self;

[_dic presentOpenInMenuFromRect:rect inView:self.view animated:YES];

【讨论】:

  • 有什么方法可以在模拟器中进行测试,还是需要在手机上进行?是否有关于这些功能的用户流程的文档? IG 开发网站在这方面缺乏。
猜你喜欢
  • 1970-01-01
  • 2011-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-27
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
相关资源
最近更新 更多