ios - 使用 Document Interaction Controller 直接发布到 instagram

标签 ios instagram uidocumentinteraction

在我的应用程序中,我设法通过文档交互 Controller 将图像发布到 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;
}

最佳答案

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

关于ios - 使用 Document Interaction Controller 直接发布到 instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22150080/

相关文章:

java - 如何将 Instagram 媒体对象中的created_at字段值转换为日期

objective-c - UIDocumentInteractionController : "Open In" visible on iPhone but not on iPad - why?

ios - 如何将 iOS 订阅与现有的订阅网络服务一起使用?

objective-c - Xcode 4.5 GM 上的 Restkit 在 iOS 6 设备上不起作用 - 文件是为存档构建的,不是链接的体系结构

iOS 9 Swift 2 : horizontally scrollable views? Facebook 的 "suggested friends/groups"

instagram - 如何从 Instagram 上的多张照片帖子中检索所有图像

ios - CFBundleVersion 不匹配 - CFBundleVersion 值与其包含的 iOS 应用程序的 CFBundleVersion 值不匹配

javascript - 如何修复 Puppeteer 抛出的 "Node is either not visible or not an HTMLElement"错误?

ios - 如何将 "Open in.."函数添加到自定义 UIWebview?

iOS 发布到 Instagram 不工作