【问题标题】:Unable to get a URL from assets-library无法从资产库中获取 URL
【发布时间】:2017-04-29 21:06:36
【问题描述】:

我想将图像发送到服务器,我正在显示来自UIImagePickerControllerPhotoLibrary

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

但它以我不想要的资产库的格式显示(我的日志输出)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

我如何做到这一点?

请提前帮助和感谢!

【问题讨论】:

标签: ios iphone ipad afnetworking icloud


【解决方案1】:

我不知道您为什么需要这样做。不过你可以试试。

- (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);
    }];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-02
    • 2017-02-09
    • 2022-01-25
    • 2014-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多