【问题标题】:Instagram Video iPhone HookInstagram 视频 iPhone 挂钩
【发布时间】:2014-10-14 18:32:35
【问题描述】:

目前最好的解决方案:

https://stackoverflow.com/a/21888830/1786820

我正在尝试做得更好,方法是打开 Instagram 应用程序,其中包含来自 PhotoRoll 的预选视频文件和预加载的标题。在 Flipagram 应用程序中,他们就是这样做的。当您在视频上点击分享时,他们会将其保存在您的相机胶卷上,建议标题,然后直接进入 Instagram 应用程序的照片选择屏幕,并预先选择视频。即使视频不是 PhotoRoll 中的最新媒体,它也会正确地突出显示正确的视频,以及在 Flipagram 应用程序中准备的标题。

这可能是一个未记录的 iPhone 挂钩吗?

感谢任何帮助。

【问题讨论】:

    标签: ios instagram


    【解决方案1】:

    我想出了让我的应用接受 instagram:// URL 架构的想法。 Flipagram 的钩子在我的应用中打开如下:

    instagram://library?AssetPath=assets-library%3A%2F%2Fasset%2Fasset.mp4%3Fid%3D8864C466-A45C-4C48-B76F-E3C421711E9D%26ext%3Dmp4&InstagramCaption=Some%20Preloaded%20Caption

    未记录的 iPhone 挂钩可让您自动从 iPhone 相册中选择资源,并为视频预加载字幕。这应该为您提供与 Flipagrams 应用程序在将视频分享到 Instagram 时相同的用户体验。

    NSURL *videoFilePath = ...; // Your local path to the video
    NSString *caption = @"Some Preloaded Caption";
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:videoFilePath] completionBlock:^(NSURL *assetURL, NSError *error) {
        NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",[assetURL absoluteString].percentEscape,caption.percentEscape]];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
            [[UIApplication sharedApplication] openURL:instagramURL];
        }
    }];
    

    效果很好!

    更新: Instagram 已经取消了将标题传递给他们的应用程序的功能。现在最好的解决方案是将所需的标题复制到粘贴板上。

    【讨论】:

    • 快速说明:似乎有必要将打开新保存资产的 URL 延迟几秒钟。否则倒数第二个视频将被选中。
    • 如果我想添加字幕,那么这对我不起作用,所以还有其他选项可以添加带有视频文件的字幕以在 instagram 上共享吗?
    • @Ashish 您可能需要确保在构建要发送到 Instagram 的 URL 之前对标题进行 URL 编码。
    • 是的,我正在以编码格式发送 url,但我还必须对标题进行编码才能将其发送到 Instagram?
    • 对于 IOS 9stringByAddingPercentEscapesUsingEncoding 已被弃用,因此您将不得不使用 stringByAddingPercentEncodingWithAllowedCharacters,但 URLPathAllowedCharacterSet()alphanumericCharacterSet() 都不足以产生相同的结果输出如上。解决方案是附加alphanumericCharacterSet(),例如:let characterSet = NSMutableCharacterSet.alphanumericCharacterSet() characterSet.addCharactersInString("-.") //add dash and period to list
    【解决方案2】:

    答案是它根本没有从相机胶卷中提取视频,它可能看起来就是这样。

    此处的文档:http://instagram.com/developer/mobile-sharing/iphone-hooks/

    相关位是底部的“文档交互”部分。

    你可以这样做:

    NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"instagram.igo"];
    NSData *data = // set this yourself
    
    NSError *error = nil;
    if (! [data writeToFile:filePath options:NSDataWritingAtomic error:&error])
    {
        // error here
    }
    
    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
    self.documentInteractionController.delegate = self;
    self.documentInteractionController.UTI = @"com.instagram.exclusivegram";
    self.documentInteractionController.annotation = @{ @"InstagramCaption" : @"caption text here" };
    const BOOL couldOpen = [self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:myView animated:YES];
    

    设置您自己呈现的数据、标题和视图。注意UIDocumentInteractionController 也是一个属性。它应该保留在某个地方,而不仅仅是方法中的局部变量,因为当方法完成时它需要存在于该范围之外。

    【讨论】:

    • 这似乎适用于图像,但不适用于视频。我只是得到一个黑色的图像。我猜这是一个 iPhone Hook,因为文档交互视图从未出现在 Flipagrams 应用程序中。
    猜你喜欢
    • 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
    相关资源
    最近更新 更多