美文网首页
PHImageFileURLKey对应的值没数据

PHImageFileURLKey对应的值没数据

作者: 恩莱客 | 来源:发表于2019-05-17 13:33 被阅读0次
#pragma mark -imagePickerController delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:NO completion:nil];
    NSMutableDictionary *mediaInfo = [[NSMutableDictionary alloc] initWithDictionary:info];
    UIImage *tempImage ;
    tempImage = [mediaInfo objectForKey:UIImagePickerControllerOriginalImage];
    //保证图片方向正向
    UIImage *upImage = [CommUtls fixOrientation:tempImage];
    UIImage *compressImage = [[ImageCompression shareImageCompression] compessImage:upImage comWidth:640 comHeight:972];
    
    NSDictionary *imageInfo = nil;
    //获取本地路径
    if (info[@"PHImageFileURLKey"]) {
      imageInfo = [NSDictionary dictionaryWithObjectsAndKeys:compressImage,@"image", [NSNumber numberWithFloat:ratio],@"ratio", [info[@"PHImageFileURLKey"] absoluteString],  @"local_path", nil];
    }else{
      imageInfo = [NSDictionary dictionaryWithObjectsAndKeys:compressImage,@"image", [NSNumber numberWithFloat:ratio],@"ratio", nil];
}
    [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_TRANSTER_IMAGE object:imageInfo];
    }
}

获取本地图片功能,对应key为PHImageFileURLKey,注意通过PHImageFileURLKey会有空的情况,需要添加空判断。
Stack Overflow给出的解决方案:

PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc] init];
 [[PHImageManager defaultManager]
             requestImageDataForAsset:asset
                            options:imageRequestOptions
                      resultHandler:^(NSData *imageData, NSString *dataUTI,
                                      UIImageOrientation orientation, 
                                      NSDictionary *info) 
     {
          NSLog(@"info = %@", info);
          if ([info objectForKey:@"PHImageFileURLKey"]) {

               NSURL *path = [info objectForKey:@"PHImageFileURLKey"];
               // if you want to save image in document see this.
               [self saveimageindocument:imageData withimagename:[NSString stringWithFormat:@"DEMO"]];
          }                                            
    }];

-(void) saveimageindocument:(NSData*) imageData withimagename:(NSString*)imagename{
    NSString *writePath = [NSString stringWithFormat:@"%@/%@.png",[Utility getDocumentDirectory],imagename];
    if (![imageData writeToFile:writePath atomically:YES]) {
        // failure
        NSLog(@"image save failed to path %@", writePath);

    } else {
        // success.
        NSLog(@"image save Successfully to path %@", writePath);
    }

}
+ (NSString*)getDocumentDirectory {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [paths objectAtIndex:0];
}

相关文章

  • PHImageFileURLKey对应的值没数据

    获取本地图片功能,对应key为PHImageFileURLKey,注意通过PHImageFileURLKey会有空...

  • Django 一对一学生表与学号表对应关系建立数据库表

    所谓的一对一关系就是数据库里两个数据表的id对应相等的值数据库字段相互联系对应, 删除主表从表数据也对应删除可在从...

  • 钉钉小程序

    1. setData 改变对应的this.data的值 注意:不要直接修改this.data对应的数据。在dd.h...

  • 【python】数据清洗

    1.处理缺失值 判断是否含缺失值/统计缺失值 筛选所有含缺失值的表格 删除含缺失值的数据 用新值填充空值 对应值替...

  • XPS荷电校正

    首先打开XPS数据,找到C1s数据 找到B列数据最大值对应的A列值 其校正值为284.6-283.5=1.1eV

  • JS引用类型值和基本类型值

    数据类型中分为五种简单的数据类型和一种复杂的数据类型。他们分别对应着基本类型值和引用类型值。基本类型值有:null...

  • Day 4

    一.recode 1.变量 变量名 = 值 python中所有的变量都是保存数据的地址, 使用的是地址对应的值 值...

  • 2020-08-11DML增删改表中的数据

    添加数据 insert into 表名(列名,列名)values (值,值) 注意:①列名和值要一一对应②如果表名...

  • java数据丢失解决方案

    解决数据丢失问题 数据丢失(在修改的时候---在传参的时候有些值没有传过去。对应的值就为空。但是执行SQL还在执行...

  • vue开发中踩过的坑

    watch 它用于观察Vue实例上的数据变动。对应一个对象,键是观察表达式,值是对应回调。值也可以是方法名,或者是...

网友评论

      本文标题:PHImageFileURLKey对应的值没数据

      本文链接:https://www.haomeiwen.com/subject/zypnaqtx.html