1

Using UIImagePickerController, I'm able to get the Asset Path for a Media like assets-library://asset/asset.MOV?id=2A2CE6C9-C178-4395-977B-E6F159BF6D5E&ext=MOV.

NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",[referenceURL absoluteString], strInstagramCaption]];

Now, I want to convert this Asset Path into NSURL to pass it into following code block :

if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
    [[UIApplication sharedApplication] openURL:instagramURL];
}
Vaibhav Jhaveri
  • 1,579
  • 3
  • 28
  • 53
  • Can I ask you a question. When you do this, do you find that the Instagram app sometimes goes to the image/video which was added before? So in other words it opens up the second to latest one for some reason? –  Jun 01 '15 at 09:21
  • No, the above instagramURL opens Home tab of Instagram App – Vaibhav Jhaveri Jun 01 '15 at 09:23
  • Well I have been testing it and it opens the Photo/Video uploader. –  Jun 01 '15 at 09:26
  • Can you please share the whole code ? – Vaibhav Jhaveri Jun 01 '15 at 09:27
  • I am basically using the code from this post: http://stackoverflow.com/a/27702493/4657588 –  Jun 01 '15 at 09:29
  • I want `assets-library://asset/asset.JPG?id=B202E621-FCCB-48BA-817C-8DF9605ED799&ext=JPG` path from `/var/mobile/Containers/Data/Application/ABADEDFA-FDEE-47BA-A7F5-575AAA40F937/Documents/InstaImage.png` path. Please help – Vaibhav Jhaveri Jun 02 '15 at 05:29
  • Ok I added an answer, I think it may solve your problem. –  Jun 02 '15 at 07:50

2 Answers2

1

This is the way how you should convert asset path to valid NSUrl:-

NSURL *instagramURL = [NSURL URLWithString:[[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",[assetURL absoluteString],caption]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
        [[UIApplication sharedApplication] openURL:instagramURL];
    }

Referred from this

Community
  • 1
  • 1
Vizllx
  • 9,135
  • 1
  • 41
  • 79
0

I presume you would have used UIImagePickerController to select a photo from the library or to bring up the camera? Either way you must be making use of the following delegate method:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

}

Well in that method, you can get the URL of the asset and then pass that to AVAsset framework for the asset URL and then put that in the Instagram URL.

(NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];

Use the above code to obtain a URL for the image in the imagePickerController delegate method. You can then pass that to AVAsset.

Update This is also a useful link to look at, its explains how to use UIImagePickerController - http://www.appcoda.com/ios-programming-camera-iphone-app/.

Hope this helps :)