在我的应用程序中,我设法通过文档交互控制器将图像发布到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;
}
答案 0 :(得分:2)
方法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];