【问题标题】:Caption does not appear on Instagram photo after setting UIDocumentInteractionController's annotation property设置 UIDocumentInteractionController 的 annotation 属性后,标题不会出现在 Instagram 照片上
【发布时间】:2014-07-25 20:26:27
【问题描述】:

我的应用可以使用 UIDocumentInteractionController 成功将照片上传到 Instagram,但我无法成功上传带有标题的照片。

Instagram 文档告诉您这样做:

要在照片中包含预填充的标题,您可以设置 文档交互请求上的注释属性 NSDictionary 包含键“InstagramCaption”下的 NSString。 注意:此功能将在 Instagram 2.1 及更高版本上可用。

我已经尝试了五次了。我尝试了几种不同的方法创建NSDictionary,包括使用文字语法,但我仍然无法让它工作,所以它一定是 Instagram 的问题。

这是我的代码示例,用于设置文档并在 Instagram iOS 应用中打开照片:

UIImage *screenShot = finalImage;
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.igo"];

[UIImagePNGRepresentation(screenShot) writeToFile:savePath atomically:YES];

CGRect rect = CGRectMake(0 ,0 , 0, 0);
NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.igo"];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];

self.dic.UTI = @"com.instagram.photo";
self.dic.annotation = @{@"InstagramCaption" : @"Here's my caption!"};

self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.dic presentOpenInMenuFromRect:rect inView:self.view animated:YES];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];

if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {

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

} else {

    NSLog(@"No Instagram Found");
}
}

注意我如何正确设置 self.dic.annotation 并遵循 Instagram 的指南。

照片在 Instagram iOS 应用中打开良好,并将成功上传到用户的个人资料,但从未包含标题。

看起来人们在 2013 年也遇到过同样的问题,但后来问题得到了解决。

【问题讨论】:

标签: ios objective-c instagram uidocumentinteraction


【解决方案1】:

我刚刚想通了。

我所做的只是将我的语句移动到我在以下语句下方定义self.dic.annotation 的位置:

self.dic = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];

上面的语句返回了一个UIDocumentInteractionController 的新实例,显然它的所有属性都没有设置。

编辑:我建议不要使用我发布的原始代码,除非您愿意进行更改。我刚刚注意到有两个语句返回一个 UIDocumentInteractionController 实例,它们都彼此相邻:

self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];

此代码来自教程,因此我无法保证其质量。如果您想使用它,请确保逐行分析它,这样您就不会遇到我所做的任何混淆。

编辑 2:

这是完美运行的最终代码示例。您应该可以毫无错误地使用它:

UIImage *screenShot = finalImage;

NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.igo"];

[UIImagePNGRepresentation(screenShot) writeToFile:savePath atomically:YES];

CGRect rect = CGRectMake(0 ,0 , 0, 0);
NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.igo"];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];

self.dic = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.dic.UTI = @"com.instagram.photo";
self.dic.annotation = [NSDictionary dictionaryWithObject:@"Enter your caption here" forKey:@"InstagramCaption"];

[self.dic presentOpenInMenuFromRect:rect inView:self.view animated:YES];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];

 if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {

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

    } else {

        NSLog(@"No Instagram Found");
    }

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多