Commit a0a95e20123b7b599558bf9bed2a9493179c2a9e
1 parent
77358f2e08
Exists in
master
and in
1 other branch
update param upload-image
Showing 2 changed files with 36 additions and 26 deletions Side-by-side Diff
LifeLog/LifeLog/RegisterViewController.m
| ... | ... | @@ -184,8 +184,14 @@ |
| 184 | 184 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info |
| 185 | 185 | { |
| 186 | 186 | UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; |
| 187 | - self.avatar.image = image; | |
| 188 | - NSData *dataImage = UIImagePNGRepresentation(image); | |
| 187 | + //NSData *imageData = UIImageJPEGRepresentation (image, 0.5); | |
| 188 | + | |
| 189 | + // My image view is 90x90 | |
| 190 | + //UIImage *thumbImage = MyCreateThumbnailImageFromData(imageData, 90); | |
| 191 | + UIImage *thumbImage = [self imageWithImage:image scaledToFillSize:CGSizeMake(80, 80)]; | |
| 192 | + | |
| 193 | + self.avatar.image = thumbImage; | |
| 194 | + NSData *dataImage = UIImagePNGRepresentation(thumbImage); | |
| 189 | 195 | RegisterViewController __weak *weakSelf = self; |
| 190 | 196 | [[ServerAPI server] uploadImage:nil andImageData:dataImage CompletionHandler:^(NSString *linkImage, NSError *error) { |
| 191 | 197 | if (weakSelf == nil) { |
| ... | ... | @@ -213,6 +219,23 @@ |
| 213 | 219 | }]; |
| 214 | 220 | } |
| 215 | 221 | |
| 222 | +- (UIImage *)imageWithImage:(UIImage *)image scaledToFillSize:(CGSize)size | |
| 223 | +{ | |
| 224 | + CGFloat scale = MAX(size.width/image.size.width, size.height/image.size.height); | |
| 225 | + CGFloat width = image.size.width * scale; | |
| 226 | + CGFloat height = image.size.height * scale; | |
| 227 | + CGRect imageRect = CGRectMake((size.width - width)/2.0f, | |
| 228 | + (size.height - height)/2.0f, | |
| 229 | + width, | |
| 230 | + height); | |
| 231 | + | |
| 232 | + UIGraphicsBeginImageContextWithOptions(size, NO, 0); | |
| 233 | + [image drawInRect:imageRect]; | |
| 234 | + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); | |
| 235 | + UIGraphicsEndImageContext(); | |
| 236 | + return newImage; | |
| 237 | +} | |
| 238 | + | |
| 216 | 239 | #pragma mark - Function Private |
| 217 | 240 | - (void)showCamera { |
| 218 | 241 | if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) |
| ... | ... | @@ -390,16 +413,6 @@ |
| 390 | 413 | return dict; |
| 391 | 414 | } |
| 392 | 415 | |
| 393 | -/* | |
| 394 | - API regist: | |
| 395 | - - Url: http://clover.timesfun.jp:9001/register | |
| 396 | - Params: | |
| 397 | - username: "sonle33", password: "laslas123", full_name: "son le", nickname: "las", birthday: "1990-11-11", height: 177, weight: 70, fat_rate: 12, gender: 1, address: "asdsad", description: "nothing", receive_notification: 0, phone: 0988999777, share_data: 1, profile_image: "upload/avt/2019525859598528205222222.png", delete_flag: 0, email: "sonle33@las.vn", physical_activity: 0, remember_me: 1 | |
| 398 | - | |
| 399 | - - Url: http://clover.timesfun.jp:9001/forgetPass | |
| 400 | - param: email | |
| 401 | - */ | |
| 402 | - | |
| 403 | 416 | - (NSDictionary *)createParamsForRegisterUser { |
| 404 | 417 | NSMutableDictionary *dictResutl = [[NSMutableDictionary alloc] init]; |
| 405 | 418 | dictResutl = [self addParam:@"username" value:_tfUsername.text withDict:dictResutl]; |
| 406 | 419 | |
| ... | ... | @@ -407,13 +420,13 @@ |
| 407 | 420 | dictResutl = [self addParam:@"nickname" value:_tfNickname.text withDict:dictResutl]; |
| 408 | 421 | dictResutl = [self addParam:@"email" value:_tfEmail.text withDict:dictResutl]; |
| 409 | 422 | dictResutl = [self addParam:@"password" value:_tfPassword.text withDict:dictResutl]; |
| 410 | - dictResutl = [self addParam:@"confirm_password" value:_tfConfirmPassword.text withDict:dictResutl]; | |
| 423 | + //dictResutl = [self addParam:@"confirm_password" value:_tfConfirmPassword.text withDict:dictResutl]; | |
| 411 | 424 | NSString *valueSex = nil; // 0 - 男, 1 - 女 |
| 412 | 425 | if (_tflblSex.text.length > 0) { |
| 413 | 426 | if ([_tflblSex.text isEqualToString:@"男"]) { |
| 414 | 427 | valueSex = @"0"; |
| 415 | 428 | } |
| 416 | - else if ([_tflblSex.text isEqualToString:@"男"]) { | |
| 429 | + else if ([_tflblSex.text isEqualToString:@"女"]) { | |
| 417 | 430 | valueSex = @"1"; |
| 418 | 431 | } |
| 419 | 432 | } |
LifeLog/LifeLog/ServerAPI.m
| ... | ... | @@ -113,8 +113,13 @@ |
| 113 | 113 | if (error == nil) |
| 114 | 114 | { |
| 115 | 115 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
| 116 | + completion(nil); | |
| 117 | + /* | |
| 118 | + NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | |
| 119 | + if (dataResult == nil) { | |
| 120 | + completion(nil); | |
| 121 | + } | |
| 116 | 122 | |
| 117 | - | |
| 118 | 123 | int status = [dataResult[@"status"] intValue]; |
| 119 | 124 | if (status == 1) { // status = 1 success |
| 120 | 125 | completion(nil); |
| ... | ... | @@ -124,6 +129,7 @@ |
| 124 | 129 | NSError *registerFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
| 125 | 130 | completion(registerFaild); |
| 126 | 131 | } |
| 132 | + */ | |
| 127 | 133 | } |
| 128 | 134 | else |
| 129 | 135 | { |
| ... | ... | @@ -150,17 +156,8 @@ |
| 150 | 156 | if (error == nil) |
| 151 | 157 | { |
| 152 | 158 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
| 153 | - | |
| 154 | - int status = [dataResult[@"status"] intValue]; | |
| 155 | - if (status == 1) { // status = 1 success | |
| 156 | - NSString *image_profile = dataResult[@"result"][@"image_profile"]; | |
| 157 | - completion(image_profile, nil); | |
| 158 | - } | |
| 159 | - else { // status = 0 error | |
| 160 | - NSString *message = dataResult[@"message"]; | |
| 161 | - NSError *uploadFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | |
| 162 | - completion(nil, uploadFaild); | |
| 163 | - } | |
| 159 | + NSString *image_profile = [NSString stringWithFormat:@"%@", dataResult[@"message"]]; | |
| 160 | + completion(image_profile, nil); | |
| 164 | 161 | } |
| 165 | 162 | else |
| 166 | 163 | { |