使用他们的 iOS 挂钩将照片发布到 Instagram
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9061917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Post photo to Instagram using their iOS hooks
提问by AmaltasCoder
I use the following code in my iOS app to use Instagram iPhone hooks to post a photo to Instagram. I only want the "Open In..." menu to have Instagram app, no other apps. But in my case Camera+ also shows up. How can I restrict to Instagram?
我在我的 iOS 应用程序中使用以下代码来使用 Instagram iPhone 挂钩将照片发布到 Instagram。我只希望“打开方式...”菜单有 Instagram 应用程序,没有其他应用程序。但就我而言,Camera+ 也会出现。如何限制使用 Instagram?
Also, can I directly open Instagram instead of showing Open In menu?
另外,我可以直接打开 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];
}
采纳答案by cvursache
To answer only your first question: you may probably be able to restrict the "Open in ..." menu to just showing Instagram for your device (by deleting the Camera+ App, for example), but you won't be able to restrict users that install your app to their devices. And that's because the iPhone recognizes which applications are able to open a specific kind of files and it automatically show every one that does.
仅回答您的第一个问题:您可能可以将“打开方式...”菜单限制为仅显示设备的 Instagram(例如,通过删除 Camera+ 应用程序),但您将无法限制将您的应用安装到其设备上的用户。这是因为 iPhone 会识别哪些应用程序能够打开特定类型的文件,并且会自动显示每一个能够打开的文件。
回答by JoshOiknine
BTW Instagram added an exclusive file extention (ig) and UTI (com.instagram.exclusivegram) for this. It still opens the Open with... menu but the only option is Instagram.
顺便说一句,Instagram 为此添加了一个独家文件扩展名 (ig) 和 UTI (com.instagram.exclusivegram)。它仍然打开打开方式...菜单,但唯一的选项是 Instagram。
More info here: https://instagram.com/developer/mobile-sharing/iphone-hooks/
更多信息在这里:https: //instagram.com/developer/mobile-sharing/iphone-hooks/
回答by nahung89
You can get the solution from this link.
您可以从此链接获得解决方案。
Save image with the
.igo
extension instead of.ig
. This is the "exclusive" version of the filetype.Create a
UIDocumentInteractionController
, then assign the valuecom.instagram.exclusivegram
to the propertyUTI
.Present your
UIDocumentInteractionController
withpresentOpenInMenuFromRect:inView:animated
.
使用
.igo
扩展名而不是.ig
. 这是文件类型的“独占”版本。创建
UIDocumentInteractionController
,然后将值分配给com.instagram.exclusivegram
属性UTI
。展示您
UIDocumentInteractionController
的presentOpenInMenuFromRect:inView:animated
.
回答by user2421700
This worked for me, do it like this and you will have only Instagram as the exclusive app to open your image.
这对我有用,这样做,您将只有 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];
回答by utkal patel
self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];
self.documentInteractionController=[UIDocumentInteractionController interactionControllerWithURL:imgurl];
self.documentInteractionController.UTI = @"com.instagram.exclusivegram";
use this code in same sequence . here documentInteractionController is object of UIDocumentInteractionController.just for your knowledge. you will get instagram only in "open in" window.
以相同的顺序使用此代码。这里 documentInteractionController 是 UIDocumentInteractionController.just 的对象,仅供您参考。您只会在“打开方式”窗口中获得 Instagram。