Instagram hooks pre-select media issue
instagram://library?AssetPath=\(assetsLibraryUrl)
stopped working a while ago. Instagram developers probably moved to Photos framework and no longer use the AssetsLibrary.
Having this assumption I tried several other parameter names and found that instagram://library?LocalIdentifier=\(localID)
where localId
is the localIdentifier
of your PHAsset
works for now.
This is still as undocumented as it was so it can break in any future version of the Instagram.
Instagram Video iPhone Hook
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.
How can you launch Instagram's new post screen from another iOS app
There's a great post on this subject here. Basically you launch Instagram using their app URL scheme and pass a URL referencing the content in the camera roll.
How to share an image on Instagram in iOS?
Finally I got the answer. you can not directly post an image on instagram. You have to rediredt your image with UIDocumentInteractionController.
@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]];
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;
}
NOTE : once you redirect to instagram app you can not back to your app. you have to open your app again
Download source from here
Related Topics
Constant Movement in Spritekit
Apple Push Notification Limitation
Create Movie from [Uiimage], Swift
How to Determine Which Textfield Is Active Swift
Swift Optional Chaining Doesn't Work in Closure
How to Edit Uialertaction Title Font Size and Style
Applicationwillterminate: Not Being Called
Parsing JSON Within JSON in Objective-C
iPhone Uibutton - Image Position
Get Pixel Value from Cvpixelbufferref in Swift
Resize the Screen When Keyboard Appears
Setting Up a Parent-Child Relationship in Core Data
Passing Data Back from a Modal View in Watchkit
iOS 10, Nsuserdefaults Does Not Work
Increment Uislider by 1 in Range 1 to 100