1.
/**
* 上传多张照片
*
* @param imageDic 字典数组
*/
- (void)sendTopicImageToServer:(NSMutableDictionary *)imageDic{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
[manager POST:SEND_TOPIC_IMAGE parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//图片上传
if (imageDic.count > 0) {
for (NSString *key in [imageDic allKeys]) {
[formData appendPartWithFileData:[imageDic objectForKey:key] name:key fileName:[NSString stringWithFormat:@"%@.png",key] mimeType:@"image/jpeg"];
}
[self initMBProgress:@"图片上传中..."];
}
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
[self setMBProgreeHiden:YES];
self.imagesArray = [responseObject objectForKey:@"Detail"];
/**
* 发布图片和内容到服务器
*/
if (sendTopicView.titleTextField.text.length<1) {
[self initMBProgress:@"标题不能为空" withModeType:MBProgressHUDModeText afterDelay:1];
return;
}
SharedInfo *sharedInfo = [SharedInfo sharedDataInfo];
NSDictionary *params = @{@"Method":@"AddPostInfo",@"RunnerUserID":sharedInfo.user_id,@"RunnerIsClient":@"1",@"RunnerIP":@"2",@"Detail":@[@{@"ClassID":self.cate_id,@"Name":sendTopicView.titleTextField.text,@"IsShow":@"1",@"Detail":sendTopicView.contentTextView.text,@"Sort":@"",@"UserID":sharedInfo.user_id,@"IP":@"",@"ProvinceID":isStrEmpty(sharedInfo.area)?@"1":sharedInfo.area,@"CityID":isStrEmpty(sharedInfo.city)?@"1":sharedInfo.city}],@"Images":self.imagesArray};
[CKHttpRequest createRequest:HTTP_COMMAND_SEND_TOPIC WithParam:params withMethod:@"POST" success:^(id result) {
if (result && [[result objectForKey:@"Success"]intValue] > 0) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
[self initMBProgress:@"发布成功" withModeType:MBProgressHUDModeText afterDelay:1];
}];
}else{
[self initMBProgress:[result objectForKey:@"Msg"] withModeType:MBProgressHUDModeText afterDelay:1.5];
}
} failure:^(NSError *erro) {
}];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
- (void)sendTopicAction{
for (int i = 0; i < _locaPhotoArr.count; i ++) {
NSDictionary *dict = [_locaPhotoArr objectAtIndex:i];
UIImage *image = [dict objectForKey:UIImagePickerControllerOriginalImage];
NSString *indexStr = [NSString stringWithFormat:@"picturename%d",i];
NSData *imageData = UIImageJPEGRepresentation(image, 0.0f);
[Exparams addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys:imageData,indexStr, nil]];
}
[self sendTopicImageToServer:Exparams];
}