Create NSURL using AssetPath

半城伤御伤魂 提交于 2019-12-20 05:05:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!