在iOS上如何在Instagram上分享带有图片的文本

8

我在我的应用程序中分享了一张图片到Instagram。这在我的应用程序中运行良好。

我正在使用以下代码。

@property (nonatomic, retain) UIDocumentInteractionController *dic;    

CGRect rect = CGRectMake(0 ,0 , 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];

NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
//    NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", screenshot]];

self.dic.UTI = @"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.dic presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];


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

现在我想分享一些与图片相关的文本。

如下图所示,在“写标题”中,我想要一些默认的自定义文本,例如“分享这张照片”。

我该怎么做?

谢谢提前...

enter image description here

编辑

我正在从我的应用程序中打开 Instagram 以共享图像,它运行良好。

但是,我可以检查用户是否成功共享了吗?

也就是说,当用户成功共享图像时,我想在我的数据库中执行某些操作。

我该如何做到这一点?

3个回答

14

我已经得到了答案。只需添加一行代码,它就对我起作用了。

self.dic.annotation = [NSDictionary dictionaryWithObject:@"Here Give what you want to share" forKey:@"InstagramCaption"];

谢谢...


添加文本和图片的其他设置是什么? - Ankit Kargathra

3

官方文档也记录在http://instagram.com/developer/iphone-hooks/

如果您想在照片中包含预填充的标题,可以将注释属性设置为包含NSString的NSDictionary,并将其放置在 InstagramCaption 键下。注意:此功能仅适用于Instagram 2.1及更高版本。


3
截至2015年8月,Instagram不再支持InstagramCaption注释。请参见:http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing - joshrl

2

您不再被允许与Instagram或Facebook分享预填文字。

只能通过UIDocumentInteractionController共享图像/屏幕截图。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接