关于处理上传图片的问题

最美应用有价值的好应用 2018-02-01

主要实现用户选择好照片后,一张一张上传,显示上传进度并且上传完服务器后显示图片

// 相册选的图片

- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto{

[self.dataArr addObjectsFromArray:photos];

if (self.maxImageCount == 6) {

_currentCount = self.imaUrlArr.count;

NSLog(@"取得的范围是%ld******%ld",self.imaUrlArr.count,self.dataArr.count);

[self uploadImage:photos];

for (int i = 0; i<photos.count ; i++) {

UIImage * image = [UIImage imageNamed:@"上传中"];

[self.dataArr replaceObjectAtIndex:self.imaUrlArr.count+i withObject:image];

[self reloadData];

}

}else{

[self reloadData];

}

}

#pragma mark - 单个上传图片

-(void)uploadImage:(NSArray *)arr{

static NSInteger index;

UIImage * image = arr[index];

NSData * imaData = UIImageJPEGRepresentation(image, 0.5);

[self showHudInView:self.view hint:[NSString stringWithFormat:@"正在上传第%ld张",index+1]];

[DNNetworking postWithURLString:strWith(@"upload",version02) parameters:nil imageData:imaData fileName:@"uploadFile" progress:^(NSProgress *progress) {

} success:^(id obj) {

if ([NSString isEmptyOfString:obj[@"image"]] == NO){

NSLog(@"最终i的值为%ld",index);

[self reloadItemCellWithItem:index AndOrginArr:arr];

[_imaUrlArr addObject:obj[@"image"]];

index++;

[self hideHud];

if (index+1>arr.count) {

index = 0;

}else{

[self uploadImage:arr];

}

NSString *text = [self.imaUrlArr componentsJoinedByString:@","];

NSLog(@"%@",text);

}else

ShowInfoWithStatus(obj[@"errorMessage"]);

} failure:^(NSError *error) {

}];

}

#pragma mark - 单个加载完图片之后显示

-(void)reloadItemCellWithItem:(NSInteger)item AndOrginArr:(NSArray *)arr{

NSLog(@"%ld呵呵呵呵呵呵呵呵呵呵呵呵呵呵%ld*******arr的count%ld",item,item+_currentCount,arr.count);

[self.dataArr replaceObjectAtIndex:item+_currentCount withObject:arr[item]];

[self reloadData];

}

相关推荐