问题
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];
}
回答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
回答2:
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 :)
来源:https://stackoverflow.com/questions/30566795/create-nsurl-using-assetpath