Instagram Video iPhone Hook

后端 未结 2 522
迷失自我
迷失自我 2021-01-01 07:37

The current best solution:

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

I am trying to do one better, by opening the Instagram app with a preselected video f

2条回答
  •  一向
    一向 (楼主)
    2021-01-01 08:03

    I came up with the idea to allow my app to accept the instagram:// URL schema. The hook from Flipagram opened up in my app as the following:

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

    The undocumented iPhone hook that allows you to automatically select assets from the iPhones photo roll, and preload a caption for the video. This should give you the same user experience that Flipagrams app has with sharing a video to 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];
        }
    }];
    

    Works great!

    Update: Instagram has removed the ability to pass the caption to their app. The best solution now it to just copy the desired caption to the paste board.

提交回复
热议问题