【问题标题】:UIDocumentInteractionController annotation property doesn't copy caption to presented applicationUIDocumentInteractionController 注释属性不会将标题复制到呈现的应用程序
【发布时间】:2019-11-21 21:15:25
【问题描述】:

感谢这里的其他几篇文章,我已经成功地能够使用 Instagram iPhone 挂钩打开 Instagram 并成功地向它展示我的应用程序中的照片。

(我已经将我的ViewController 类设置为UIDocumentInteractionControllerdelegatealloc/initnonatomic/retain propertyUIDocumentInteractionController...

但是,我放入我的 NSDictionary 中并放置在文档控制器注释属性中的密钥 不会 转移到 Instagram - 标题区域只是空的。

我该如何处理?

这是我的方法:

- (void) uploadImageToInstagram:(UIImage *)imageToUpload {
    NSLog(@"postToInstagramInBackground");

    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {

        // Upscale to 612x612
        imageToUpload = [self upscaleImage:imageToUpload];

        // Get JPG + IGO Format
        NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/generate.igo"];
        [UIImageJPEGRepresentation(imageToUpload, 1.0) writeToFile:savePath atomically:YES];

        // Paths
        NSURL *imageURL = [NSURL fileURLWithPath:savePath];
        NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@",savePath]];

        // Setup DocController
        self.docController.UTI = @"com.instagram.photo";
        self.docController = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
        self.docController.annotation = [NSDictionary dictionaryWithObject:@"MyApp" forKey:self.caption.text];
        [self.docController setURL:imageURL];
        [self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES ];
    }
    else {
        NSLog(@"Instagram not installed in this device!\nTo share image please install Instagram.");
    }
}

这里调用了一些我没有包含的方法,一种是放大图像以确保其 612x612,另一种是为文档控制器设置文件 url。

【问题讨论】:

  • 我对发布到 instagram 一无所知,但您将注释设置为对象为“MyApp”且键为标题文本的字典。你不需要扭转它吗?
  • 哦,真的吗?我对 NSDictionary 不是很熟悉,但是我在网上看到的示例有对象的名称和他的键的标题......肯定是错的...... IDK。我只是试图扭转它们,它仍然没有工作......
  • 你是对的......正确的语法应该是标题作为对象,键应该是@"InstagramCaption"
  • 很高兴我能帮上忙 :)... 只是在黑暗中拍摄。通常像这样的 API 会有键的常量,并且你的自定义数据应该在对象中。这样它就可以准确地知道要在字典中查找哪些键

标签: ios objective-c ios7 instagram uidocumentinteraction


【解决方案1】:

正确的语法应该是

self.docController.annotation = [NSDictionary dictionaryWithObject:self.caption.text forKey:@"InstagramCaption"];

【讨论】:

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