无法从assets-library获取URL

时间:2016-12-14 13:47:52

标签: ios iphone ipad afnetworking icloud

我想将图片发送到服务器,我正在PhotoLibrary显示UIImagePickerController

每当用户从ImagePicker中选择任何照片时,我都会选择图像的网址。

但它以资产库的格式显示我不想要的(我的日志输出)localUrl =assets-library://asset/asset.JPG?id=106E99A1-4F6A-45A2-B320-B0AD4A8E8473&ext=JPG

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^{

        NSURL* localUrl = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
        NSLog(@"localUrl =%@",localUrl);

    }];

}

我希望它的格式为file:///Users/Library/Developer/CoreSimulator/Devices/85CBED11-A318-4096-B52A-EBC3879F7B34/data/Containers/Data/Application/805BB62D-E32E-4D1E-99B6-C91103A1D99B/tmp/testing.doc

我如何实现这一目标?

请提前帮助和致谢!

1 个答案:

答案 0 :(得分:0)

我不知道为什么你需要做这个案子。但你可以尝试一下。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^{    
       NSData *pngData = UIImagePNGRepresentation(ivPickedImage.image);
       NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
       NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
       NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"]; //Add the file name
      [pngData writeToFile:filePath atomically:YES]; //Write the file
       NSLog(@"localUrl =%@",filePath);
    }];
}