Commit a38638ea91c447df9909d434f1dbddba13838e60

Authored by nvtu
1 parent 67297da306
Exists in master

fix register api

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

LifeLog/LifeLog/RegisterViewController.m
1 // 1 //
2 // RegisterViewController.m 2 // RegisterViewController.m
3 // LifeLog 3 // LifeLog
4 // 4 //
5 // Created by Panasonic R&D Center Vietnam on 7/31/17. 5 // Created by Panasonic R&D Center Vietnam on 7/31/17.
6 // Copyright © 2017 PhongNV. All rights reserved. 6 // Copyright © 2017 PhongNV. All rights reserved.
7 // 7 //
8 8
9 #import "RegisterViewController.h" 9 #import "RegisterViewController.h"
10 #import "CustomTextField.h" 10 #import "CustomTextField.h"
11 #import "Utilities.h" 11 #import "Utilities.h"
12 #import "NSDate+helper.h" 12 #import "NSDate+helper.h"
13 #import "ServerAPI.h" 13 #import "ServerAPI.h"
14 #import "AppDelegate.h" 14 #import "AppDelegate.h"
15 static int const kPickerTagArea = 1; 15 static int const kPickerTagArea = 1;
16 static int const kPickerTagSex = 2; 16 static int const kPickerTagSex = 2;
17 17
18 @interface RegisterViewController ()<UIActionSheetDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate> 18 @interface RegisterViewController ()<UIActionSheetDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate>
19 { 19 {
20 NSInteger indexArea; 20 NSInteger indexArea;
21 UIPickerView *pickerArea; 21 UIPickerView *pickerArea;
22 22
23 UIPickerView *pickerSex; 23 UIPickerView *pickerSex;
24 UIDatePicker *pickerDate; 24 UIDatePicker *pickerDate;
25 NSDate *dateBirthDay; 25 NSDate *dateBirthDay;
26 NSString *profile_image; 26 NSString *profile_image;
27 } 27 }
28 @property (nonatomic, weak) IBOutlet UIImageView *avatar; 28 @property (nonatomic, weak) IBOutlet UIImageView *avatar;
29 29
30 @property (nonatomic, weak) IBOutlet UILabel *lblUsername; 30 @property (nonatomic, weak) IBOutlet UILabel *lblUsername;
31 @property (nonatomic, weak) IBOutlet UILabel *lblName; 31 @property (nonatomic, weak) IBOutlet UILabel *lblName;
32 @property (nonatomic, weak) IBOutlet UILabel *lblNickname; 32 @property (nonatomic, weak) IBOutlet UILabel *lblNickname;
33 @property (nonatomic, weak) IBOutlet UILabel *lblEmail; 33 @property (nonatomic, weak) IBOutlet UILabel *lblEmail;
34 @property (nonatomic, weak) IBOutlet UILabel *lblPassword; 34 @property (nonatomic, weak) IBOutlet UILabel *lblPassword;
35 @property (nonatomic, weak) IBOutlet UILabel *lblConfirmPassword; 35 @property (nonatomic, weak) IBOutlet UILabel *lblConfirmPassword;
36 @property (nonatomic, weak) IBOutlet UILabel *lblSex; 36 @property (nonatomic, weak) IBOutlet UILabel *lblSex;
37 @property (nonatomic, weak) IBOutlet UILabel *lblBirthday; 37 @property (nonatomic, weak) IBOutlet UILabel *lblBirthday;
38 @property (nonatomic, weak) IBOutlet UILabel *lblHeight; 38 @property (nonatomic, weak) IBOutlet UILabel *lblHeight;
39 @property (nonatomic, weak) IBOutlet UILabel *lblHeightUnit; 39 @property (nonatomic, weak) IBOutlet UILabel *lblHeightUnit;
40 @property (nonatomic, weak) IBOutlet UILabel *lblWeight; 40 @property (nonatomic, weak) IBOutlet UILabel *lblWeight;
41 @property (nonatomic, weak) IBOutlet UILabel *lblWeightUnit; 41 @property (nonatomic, weak) IBOutlet UILabel *lblWeightUnit;
42 @property (nonatomic, weak) IBOutlet UILabel *lblFatPercentage; 42 @property (nonatomic, weak) IBOutlet UILabel *lblFatPercentage;
43 @property (nonatomic, weak) IBOutlet UILabel *lblFatPercentageUnit; 43 @property (nonatomic, weak) IBOutlet UILabel *lblFatPercentageUnit;
44 @property (nonatomic, weak) IBOutlet UILabel *lblPhysicalActivity; 44 @property (nonatomic, weak) IBOutlet UILabel *lblPhysicalActivity;
45 @property (nonatomic, weak) IBOutlet UILabel *lblArea; 45 @property (nonatomic, weak) IBOutlet UILabel *lblArea;
46 @property (nonatomic, weak) IBOutlet UILabel *lblNote; 46 @property (nonatomic, weak) IBOutlet UILabel *lblNote;
47 47
48 @property (nonatomic, weak) IBOutlet UITextField *tfUsername; 48 @property (nonatomic, weak) IBOutlet UITextField *tfUsername;
49 @property (nonatomic, weak) IBOutlet UITextField *tfName; 49 @property (nonatomic, weak) IBOutlet UITextField *tfName;
50 @property (nonatomic, weak) IBOutlet UITextField *tfNickname; 50 @property (nonatomic, weak) IBOutlet UITextField *tfNickname;
51 @property (nonatomic, weak) IBOutlet UITextField *tfEmail; 51 @property (nonatomic, weak) IBOutlet UITextField *tfEmail;
52 @property (nonatomic, weak) IBOutlet UITextField *tfPassword; 52 @property (nonatomic, weak) IBOutlet UITextField *tfPassword;
53 @property (nonatomic, weak) IBOutlet UITextField *tfConfirmPassword; 53 @property (nonatomic, weak) IBOutlet UITextField *tfConfirmPassword;
54 @property (nonatomic, weak) IBOutlet UITextField *tflblSex; 54 @property (nonatomic, weak) IBOutlet UITextField *tflblSex;
55 @property (nonatomic, weak) IBOutlet UITextField *tfBirthday; 55 @property (nonatomic, weak) IBOutlet UITextField *tfBirthday;
56 @property (nonatomic, weak) IBOutlet UITextField *tfHeight; 56 @property (nonatomic, weak) IBOutlet UITextField *tfHeight;
57 @property (nonatomic, weak) IBOutlet UITextField *tfWeight; 57 @property (nonatomic, weak) IBOutlet UITextField *tfWeight;
58 @property (nonatomic, weak) IBOutlet UITextField *tfFatPercentage; 58 @property (nonatomic, weak) IBOutlet UITextField *tfFatPercentage;
59 @property (nonatomic, weak) IBOutlet UISegmentedControl *physicalActivity; 59 @property (nonatomic, weak) IBOutlet UISegmentedControl *physicalActivity;
60 @property (nonatomic, weak) IBOutlet CustomTextField *tfArea; 60 @property (nonatomic, weak) IBOutlet CustomTextField *tfArea;
61 @property (nonatomic, weak) IBOutlet UITextView *tvNote; 61 @property (nonatomic, weak) IBOutlet UITextView *tvNote;
62 62
63 @property (nonatomic, weak) IBOutlet UIToolbar *toolBar; 63 @property (nonatomic, weak) IBOutlet UIToolbar *toolBar;
64 @property (nonatomic, strong) NSArray *arrayArea; 64 @property (nonatomic, strong) NSArray *arrayArea;
65 @property (nonatomic, strong) NSArray *arraySex; 65 @property (nonatomic, strong) NSArray *arraySex;
66 66
67 @property (nonatomic) UIImagePickerController *imagePickerController; 67 @property (nonatomic) UIImagePickerController *imagePickerController;
68 68
69 @end 69 @end
70 70
71 @implementation RegisterViewController 71 @implementation RegisterViewController
72 72
73 - (void)viewDidLoad { 73 - (void)viewDidLoad {
74 [super viewDidLoad]; 74 [super viewDidLoad];
75 [self setupUIRegister]; 75 [self setupUIRegister];
76 76
77 _arrayArea = [[NSArray alloc] initWithObjects:@"北海道", @"青森県", @"岩手県", @"宮城県", @"秋田県", @"山形県", @"福島県", @"茨城県", @"栃木県", @"群馬県", @"埼玉県", @"千葉県", @"東京都", @"神奈川県", @"新潟県", @"富山県", @"石川県", @"福井県", @"山梨県", @"長野県", @"岐阜県", @"静岡県", @"愛知県", @"三重県", @"滋賀県", @"京都府", @"大阪府", @"兵庫県", @"奈良県", @"和歌山県", @"鳥取県", @"島根県", @"岡山県", @"広島県", @"山口県", @"徳島県", @"香川県", @"愛媛県", @"高知県", @"福岡県", @"佐賀県", @"長崎県", @"熊本県", @"大分県" , @"宮崎県", @"鹿児島県", @"沖縄県", nil]; 77 _arrayArea = [[NSArray alloc] initWithObjects:@"北海道", @"青森県", @"岩手県", @"宮城県", @"秋田県", @"山形県", @"福島県", @"茨城県", @"栃木県", @"群馬県", @"埼玉県", @"千葉県", @"東京都", @"神奈川県", @"新潟県", @"富山県", @"石川県", @"福井県", @"山梨県", @"長野県", @"岐阜県", @"静岡県", @"愛知県", @"三重県", @"滋賀県", @"京都府", @"大阪府", @"兵庫県", @"奈良県", @"和歌山県", @"鳥取県", @"島根県", @"岡山県", @"広島県", @"山口県", @"徳島県", @"香川県", @"愛媛県", @"高知県", @"福岡県", @"佐賀県", @"長崎県", @"熊本県", @"大分県" , @"宮崎県", @"鹿児島県", @"沖縄県", nil];
78 _arraySex = [[NSArray alloc] initWithObjects:@"男", @"女", nil]; 78 _arraySex = [[NSArray alloc] initWithObjects:@"男", @"女", nil];
79 79
80 pickerArea = [[UIPickerView alloc] init]; 80 pickerArea = [[UIPickerView alloc] init];
81 pickerArea.dataSource = self; 81 pickerArea.dataSource = self;
82 pickerArea.delegate = self; 82 pickerArea.delegate = self;
83 pickerArea.showsSelectionIndicator = YES; 83 pickerArea.showsSelectionIndicator = YES;
84 pickerArea.tag = kPickerTagArea; 84 pickerArea.tag = kPickerTagArea;
85 pickerArea.backgroundColor = [Utilities convertHecToColor:0x618DB6]; 85 pickerArea.backgroundColor = [Utilities convertHecToColor:0x618DB6];
86 86
87 _tfArea.inputAccessoryView = _toolBar; 87 _tfArea.inputAccessoryView = _toolBar;
88 _tfArea.inputView = pickerArea; 88 _tfArea.inputView = pickerArea;
89 //_tfArea.alpha = 0.5; 89 //_tfArea.alpha = 0.5;
90 _tfArea.delegate = self; 90 _tfArea.delegate = self;
91 91
92 pickerSex = [[UIPickerView alloc] init]; 92 pickerSex = [[UIPickerView alloc] init];
93 pickerSex.dataSource = self; 93 pickerSex.dataSource = self;
94 pickerSex.delegate = self; 94 pickerSex.delegate = self;
95 pickerSex.showsSelectionIndicator = YES; 95 pickerSex.showsSelectionIndicator = YES;
96 pickerSex.tag = kPickerTagSex; 96 pickerSex.tag = kPickerTagSex;
97 pickerSex.backgroundColor = [Utilities convertHecToColor:0x618DB6]; 97 pickerSex.backgroundColor = [Utilities convertHecToColor:0x618DB6];
98 98
99 _tflblSex.inputAccessoryView = _toolBar; 99 _tflblSex.inputAccessoryView = _toolBar;
100 _tflblSex.inputView = pickerSex; 100 _tflblSex.inputView = pickerSex;
101 //_tflblSex.alpha = 0.5; 101 //_tflblSex.alpha = 0.5;
102 _tflblSex.delegate = self; 102 _tflblSex.delegate = self;
103 103
104 pickerDate = [[UIDatePicker alloc] init]; 104 pickerDate = [[UIDatePicker alloc] init];
105 pickerDate.backgroundColor = [Utilities convertHecToColor:0x618DB6]; 105 pickerDate.backgroundColor = [Utilities convertHecToColor:0x618DB6];
106 pickerDate.datePickerMode = UIDatePickerModeDate; 106 pickerDate.datePickerMode = UIDatePickerModeDate;
107 _tfBirthday.inputAccessoryView = _toolBar; 107 _tfBirthday.inputAccessoryView = _toolBar;
108 _tfBirthday.inputView = pickerDate; 108 _tfBirthday.inputView = pickerDate;
109 //_tflblSex.alpha = 0.5; 109 //_tflblSex.alpha = 0.5;
110 _tflblSex.delegate = self; 110 _tflblSex.delegate = self;
111 profile_image = @""; 111 profile_image = @"";
112 } 112 }
113 113
114 - (void)didReceiveMemoryWarning { 114 - (void)didReceiveMemoryWarning {
115 [super didReceiveMemoryWarning]; 115 [super didReceiveMemoryWarning];
116 // Dispose of any resources that can be recreated. 116 // Dispose of any resources that can be recreated.
117 } 117 }
118 118
119 - (void)setupUIRegister 119 - (void)setupUIRegister
120 { 120 {
121 self.avatar.backgroundColor = [UIColor whiteColor]; 121 self.avatar.backgroundColor = [UIColor whiteColor];
122 self.avatar.layer.borderWidth = 2.0f; 122 self.avatar.layer.borderWidth = 2.0f;
123 self.avatar.layer.borderColor = [[UIColor whiteColor] CGColor]; 123 self.avatar.layer.borderColor = [[UIColor whiteColor] CGColor];
124 self.avatar.layer.cornerRadius = self.avatar.frame.size.width/2.0f; 124 self.avatar.layer.cornerRadius = self.avatar.frame.size.width/2.0f;
125 self.avatar.layer.masksToBounds = YES; 125 self.avatar.layer.masksToBounds = YES;
126 self.title = NSLocalizedString(@"lifelog.register.title", nil); 126 self.title = NSLocalizedString(@"lifelog.register.title", nil);
127 self.lblUsername.text = NSLocalizedString(@"lifelog.register.username", nil); 127 self.lblUsername.text = NSLocalizedString(@"lifelog.register.username", nil);
128 self.lblName.text = NSLocalizedString(@"lifelog.register.name", nil); 128 self.lblName.text = NSLocalizedString(@"lifelog.register.name", nil);
129 self.lblNickname.text = NSLocalizedString(@"lifelog.register.nickname", nil); 129 self.lblNickname.text = NSLocalizedString(@"lifelog.register.nickname", nil);
130 self.lblEmail.text = NSLocalizedString(@"lifelog.common.email", nil); 130 self.lblEmail.text = NSLocalizedString(@"lifelog.common.email", nil);
131 self.lblPassword.text = NSLocalizedString(@"lifelog.common.password", nil); 131 self.lblPassword.text = NSLocalizedString(@"lifelog.common.password", nil);
132 self.lblConfirmPassword.text = NSLocalizedString(@"lifelog.register.confirmation.password", nil); 132 self.lblConfirmPassword.text = NSLocalizedString(@"lifelog.register.confirmation.password", nil);
133 self.lblSex.text = NSLocalizedString(@"lifelog.register.sex", nil); 133 self.lblSex.text = NSLocalizedString(@"lifelog.register.sex", nil);
134 self.lblBirthday.text = NSLocalizedString(@"lifelog.register.birthday", nil); 134 self.lblBirthday.text = NSLocalizedString(@"lifelog.register.birthday", nil);
135 self.lblHeight.text = NSLocalizedString(@"lifelog.register.height", nil); 135 self.lblHeight.text = NSLocalizedString(@"lifelog.register.height", nil);
136 self.lblHeightUnit.text = NSLocalizedString(@"lifelog.register.height.unit", nil); 136 self.lblHeightUnit.text = NSLocalizedString(@"lifelog.register.height.unit", nil);
137 self.lblWeight.text = NSLocalizedString(@"lifelog.register.weight", nil); 137 self.lblWeight.text = NSLocalizedString(@"lifelog.register.weight", nil);
138 self.lblWeightUnit.text = NSLocalizedString(@"lifelog.register.weight.unit", nil); 138 self.lblWeightUnit.text = NSLocalizedString(@"lifelog.register.weight.unit", nil);
139 self.lblFatPercentage.text = NSLocalizedString(@"lifelog.register.fat.percentage", nil); 139 self.lblFatPercentage.text = NSLocalizedString(@"lifelog.register.fat.percentage", nil);
140 self.lblFatPercentageUnit.text = NSLocalizedString(@"lifelog.register.fat.percentage.unit", nil); 140 self.lblFatPercentageUnit.text = NSLocalizedString(@"lifelog.register.fat.percentage.unit", nil);
141 self.lblPhysicalActivity.text = NSLocalizedString(@"lifelog.register.daily.physical.activity.level", nil); 141 self.lblPhysicalActivity.text = NSLocalizedString(@"lifelog.register.daily.physical.activity.level", nil);
142 self.lblArea.text = NSLocalizedString(@"lifelog.register.area", nil); 142 self.lblArea.text = NSLocalizedString(@"lifelog.register.area", nil);
143 self.lblNote.text = NSLocalizedString(@"lifelog.register.note", nil); 143 self.lblNote.text = NSLocalizedString(@"lifelog.register.note", nil);
144 144
145 UIImage *img1=[UIImage imageNamed:@"icon_right"]; 145 UIImage *img1=[UIImage imageNamed:@"icon_right"];
146 CGRect frameimg1 = CGRectMake(0, 0, img1.size.width, img1.size.height); 146 CGRect frameimg1 = CGRectMake(0, 0, img1.size.width, img1.size.height);
147 UIButton *registButton=[[UIButton alloc]initWithFrame:frameimg1]; 147 UIButton *registButton=[[UIButton alloc]initWithFrame:frameimg1];
148 [registButton setBackgroundImage:img1 forState:UIControlStateNormal]; 148 [registButton setBackgroundImage:img1 forState:UIControlStateNormal];
149 [registButton addTarget:self action:@selector(registButtonPressed:) 149 [registButton addTarget:self action:@selector(registButtonPressed:)
150 forControlEvents:UIControlEventTouchUpInside]; 150 forControlEvents:UIControlEventTouchUpInside];
151 [registButton setShowsTouchWhenHighlighted:YES]; 151 [registButton setShowsTouchWhenHighlighted:YES];
152 UIBarButtonItem *barButton = [[UIBarButtonItem alloc]initWithCustomView:registButton]; 152 UIBarButtonItem *barButton = [[UIBarButtonItem alloc]initWithCustomView:registButton];
153 self.navigationItem.rightBarButtonItem = barButton; 153 self.navigationItem.rightBarButtonItem = barButton;
154 } 154 }
155 155
156 #pragma mark - Actions 156 #pragma mark - Actions
157 - (IBAction)avatarTouchUpInside:(id)sender { 157 - (IBAction)avatarTouchUpInside:(id)sender {
158 UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Avatar" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Select Camera", @"Select Photo", nil]; 158 UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Avatar" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Select Camera", @"Select Photo", nil];
159 [action showInView:self.view]; 159 [action showInView:self.view];
160 } 160 }
161 161
162 - (IBAction)registButtonPressed:(id)sender { 162 - (IBAction)registButtonPressed:(id)sender {
163 if ([self checkAllowRegister]) { 163 if ([self checkAllowRegister]) {
164 [self registerUser]; 164 [self registerUser];
165 } 165 }
166 } 166 }
167 167
168 #pragma mark - UIActionSheetDelegate 168 #pragma mark - UIActionSheetDelegate
169 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 169 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
170 switch (buttonIndex) { 170 switch (buttonIndex) {
171 case 0: 171 case 0:
172 [self showCamera]; 172 [self showCamera];
173 break; 173 break;
174 case 1: 174 case 1:
175 [self showPhoto]; 175 [self showPhoto];
176 break; 176 break;
177 default: 177 default:
178 break; 178 break;
179 } 179 }
180 } 180 }
181 181
182 #pragma mark - UIImagePickerControllerDelegate 182 #pragma mark - UIImagePickerControllerDelegate
183 183
184 // This method is called when an image has been chosen from the library or taken from the camera. 184 // This method is called when an image has been chosen from the library or taken from the camera.
185 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 185 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
186 { 186 {
187 UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; 187 UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
188 //NSData *imageData = UIImageJPEGRepresentation (image, 0.5); 188 //NSData *imageData = UIImageJPEGRepresentation (image, 0.5);
189 189
190 // My image view is 90x90 190 // My image view is 90x90
191 //UIImage *thumbImage = MyCreateThumbnailImageFromData(imageData, 90); 191 //UIImage *thumbImage = MyCreateThumbnailImageFromData(imageData, 90);
192 UIImage *thumbImage = [self imageWithImage:image scaledToFillSize:CGSizeMake(80, 80)]; 192 UIImage *thumbImage = [self imageWithImage:image scaledToFillSize:CGSizeMake(80, 80)];
193 193
194 self.avatar.image = thumbImage; 194 self.avatar.image = thumbImage;
195 NSData *dataImage = UIImagePNGRepresentation(thumbImage); 195 NSData *dataImage = UIImagePNGRepresentation(thumbImage);
196 RegisterViewController __weak *weakSelf = self; 196 RegisterViewController __weak *weakSelf = self;
197 [[ServerAPI server] uploadImage:nil andImageData:dataImage CompletionHandler:^(NSString *linkImage, NSError *error) { 197 [[ServerAPI server] uploadImage:nil andImageData:dataImage CompletionHandler:^(NSString *linkImage, NSError *error) {
198 if (weakSelf == nil) { 198 if (weakSelf == nil) {
199 return ; 199 return ;
200 } 200 }
201 if (error == nil) { 201 if (error == nil) {
202 profile_image = linkImage; 202 profile_image = linkImage;
203 } 203 }
204 else { 204 else {
205 dispatch_async(dispatch_get_main_queue(), ^{ 205 dispatch_async(dispatch_get_main_queue(), ^{
206 NSString *message = [error.userInfo objectForKey:@"message"]; 206 NSString *message = [error.userInfo objectForKey:@"message"];
207 [Utilities showErrorMessage:message withViewController:weakSelf]; 207 [Utilities showErrorMessage:message withViewController:weakSelf];
208 }); 208 });
209 } 209 }
210 }]; 210 }];
211 // Dismiss the image picker. 211 // Dismiss the image picker.
212 [self dismissViewControllerAnimated:YES completion:nil]; 212 [self dismissViewControllerAnimated:YES completion:nil];
213 _imagePickerController = nil; 213 _imagePickerController = nil;
214 } 214 }
215 215
216 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 216 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
217 { 217 {
218 [self dismissViewControllerAnimated:YES completion:^{ 218 [self dismissViewControllerAnimated:YES completion:^{
219 //.. done dismissing 219 //.. done dismissing
220 }]; 220 }];
221 } 221 }
222 222
223 - (UIImage *)imageWithImage:(UIImage *)image scaledToFillSize:(CGSize)size 223 - (UIImage *)imageWithImage:(UIImage *)image scaledToFillSize:(CGSize)size
224 { 224 {
225 CGFloat scale = MAX(size.width/image.size.width, size.height/image.size.height); 225 CGFloat scale = MAX(size.width/image.size.width, size.height/image.size.height);
226 CGFloat width = image.size.width * scale; 226 CGFloat width = image.size.width * scale;
227 CGFloat height = image.size.height * scale; 227 CGFloat height = image.size.height * scale;
228 CGRect imageRect = CGRectMake((size.width - width)/2.0f, 228 CGRect imageRect = CGRectMake((size.width - width)/2.0f,
229 (size.height - height)/2.0f, 229 (size.height - height)/2.0f,
230 width, 230 width,
231 height); 231 height);
232 232
233 UIGraphicsBeginImageContextWithOptions(size, NO, 0); 233 UIGraphicsBeginImageContextWithOptions(size, NO, 0);
234 [image drawInRect:imageRect]; 234 [image drawInRect:imageRect];
235 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 235 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
236 UIGraphicsEndImageContext(); 236 UIGraphicsEndImageContext();
237 return newImage; 237 return newImage;
238 } 238 }
239 239
240 #pragma mark - Function Private 240 #pragma mark - Function Private
241 - (void)showCamera { 241 - (void)showCamera {
242 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 242 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
243 { 243 {
244 UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 244 UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
245 imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; 245 imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
246 imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 246 imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
247 imagePickerController.delegate = self; 247 imagePickerController.delegate = self;
248 imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen; 248 imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
249 _imagePickerController = imagePickerController; // we need this for later 249 _imagePickerController = imagePickerController; // we need this for later
250 [self presentViewController:self.imagePickerController animated:YES completion:^{ 250 [self presentViewController:self.imagePickerController animated:YES completion:^{
251 //.. done presenting 251 //.. done presenting
252 }]; 252 }];
253 } 253 }
254 } 254 }
255 255
256 - (void)showPhoto { 256 - (void)showPhoto {
257 UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 257 UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
258 imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; 258 imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
259 imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 259 imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
260 imagePickerController.delegate = self; 260 imagePickerController.delegate = self;
261 imagePickerController.modalPresentationStyle = UIModalPresentationPopover; 261 imagePickerController.modalPresentationStyle = UIModalPresentationPopover;
262 _imagePickerController = imagePickerController; // we need this for later 262 _imagePickerController = imagePickerController; // we need this for later
263 [self presentViewController:self.imagePickerController animated:YES completion:^{ 263 [self presentViewController:self.imagePickerController animated:YES completion:^{
264 //.. done presenting 264 //.. done presenting
265 }]; 265 }];
266 } 266 }
267 267
268 - (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType fromButton:(UIBarButtonItem *)button 268 - (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType fromButton:(UIBarButtonItem *)button
269 { 269 {
270 if (self.avatar.isAnimating) 270 if (self.avatar.isAnimating)
271 { 271 {
272 [self.avatar stopAnimating]; 272 [self.avatar stopAnimating];
273 } 273 }
274 274
275 UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 275 UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
276 imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; 276 imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
277 imagePickerController.sourceType = sourceType; 277 imagePickerController.sourceType = sourceType;
278 imagePickerController.delegate = self; 278 imagePickerController.delegate = self;
279 imagePickerController.modalPresentationStyle = 279 imagePickerController.modalPresentationStyle =
280 (sourceType == UIImagePickerControllerSourceTypeCamera) ? UIModalPresentationFullScreen : UIModalPresentationPopover; 280 (sourceType == UIImagePickerControllerSourceTypeCamera) ? UIModalPresentationFullScreen : UIModalPresentationPopover;
281 281
282 UIPopoverPresentationController *presentationController = imagePickerController.popoverPresentationController; 282 UIPopoverPresentationController *presentationController = imagePickerController.popoverPresentationController;
283 presentationController.barButtonItem = button; // display popover from the UIBarButtonItem as an anchor 283 presentationController.barButtonItem = button; // display popover from the UIBarButtonItem as an anchor
284 presentationController.permittedArrowDirections = UIPopoverArrowDirectionAny; 284 presentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
285 285
286 if (sourceType == UIImagePickerControllerSourceTypeCamera) 286 if (sourceType == UIImagePickerControllerSourceTypeCamera)
287 { 287 {
288 // The user wants to use the camera interface. Set up our custom overlay view for the camera. 288 // The user wants to use the camera interface. Set up our custom overlay view for the camera.
289 imagePickerController.showsCameraControls = NO; 289 imagePickerController.showsCameraControls = NO;
290 290
291 /* 291 /*
292 Load the overlay view from the OverlayView nib file. Self is the File's Owner for the nib file, so the overlayView outlet is set to the main view in the nib. Pass that view to the image picker controller to use as its overlay view, and set self's reference to the view to nil. 292 Load the overlay view from the OverlayView nib file. Self is the File's Owner for the nib file, so the overlayView outlet is set to the main view in the nib. Pass that view to the image picker controller to use as its overlay view, and set self's reference to the view to nil.
293 */ 293 */
294 } 294 }
295 295
296 _imagePickerController = imagePickerController; // we need this for later 296 _imagePickerController = imagePickerController; // we need this for later
297 297
298 [self presentViewController:self.imagePickerController animated:YES completion:^{ 298 [self presentViewController:self.imagePickerController animated:YES completion:^{
299 //.. done presenting 299 //.. done presenting
300 }]; 300 }];
301 } 301 }
302 302
303 - (IBAction)donePicker:(id)sender 303 - (IBAction)donePicker:(id)sender
304 { 304 {
305 [_tfArea resignFirstResponder]; 305 [_tfArea resignFirstResponder];
306 [_tflblSex resignFirstResponder]; 306 [_tflblSex resignFirstResponder];
307 if ([_tfBirthday becomeFirstResponder]) { 307 if ([_tfBirthday becomeFirstResponder]) {
308 [_tfBirthday resignFirstResponder]; 308 [_tfBirthday resignFirstResponder];
309 dateBirthDay = pickerDate.date; 309 dateBirthDay = pickerDate.date;
310 _tfBirthday.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[dateBirthDay getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[dateBirthDay getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[dateBirthDay getDay], NSLocalizedString(@"lifelog.common.day", nil)]; 310 _tfBirthday.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[dateBirthDay getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[dateBirthDay getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[dateBirthDay getDay], NSLocalizedString(@"lifelog.common.day", nil)];
311 } 311 }
312 } 312 }
313 313
314 #pragma mark - UITextFieldDelegate 314 #pragma mark - UITextFieldDelegate
315 - (void)textFieldDidEndEditing:(UITextField *)textField { 315 - (void)textFieldDidEndEditing:(UITextField *)textField {
316 //if (textField == _tfArea) { 316 //if (textField == _tfArea) {
317 [textField resignFirstResponder]; 317 [textField resignFirstResponder];
318 //} 318 //}
319 } 319 }
320 320
321 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 321 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
322 { 322 {
323 //if (textField == _tfArea) { 323 //if (textField == _tfArea) {
324 [textField resignFirstResponder]; 324 [textField resignFirstResponder];
325 return NO; 325 return NO;
326 //} 326 //}
327 //else { 327 //else {
328 return YES; 328 return YES;
329 //} 329 //}
330 } 330 }
331 331
332 - (BOOL)textFieldShouldReturn:(UITextField *)textField 332 - (BOOL)textFieldShouldReturn:(UITextField *)textField
333 { 333 {
334 [textField resignFirstResponder]; 334 [textField resignFirstResponder];
335 return YES; 335 return YES;
336 } 336 }
337 337
338 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 338 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
339 //if (textField == _tfArea) { 339 //if (textField == _tfArea) {
340 [textField resignFirstResponder]; 340 [textField resignFirstResponder];
341 //} 341 //}
342 return YES; 342 return YES;
343 } 343 }
344 344
345 - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { 345 - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
346 //if (textField == _tfArea) { 346 //if (textField == _tfArea) {
347 [textField resignFirstResponder]; 347 [textField resignFirstResponder];
348 //} 348 //}
349 return YES; 349 return YES;
350 } 350 }
351 351
352 #pragma mark - UIPickerViewDataSource 352 #pragma mark - UIPickerViewDataSource
353 353
354 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 354 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
355 { 355 {
356 return 1; 356 return 1;
357 } 357 }
358 358
359 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 359 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
360 { 360 {
361 int tag = (int)pickerView.tag; 361 int tag = (int)pickerView.tag;
362 switch (tag) { 362 switch (tag) {
363 case kPickerTagArea: 363 case kPickerTagArea:
364 return _arrayArea.count; 364 return _arrayArea.count;
365 case kPickerTagSex: 365 case kPickerTagSex:
366 return _arraySex.count; 366 return _arraySex.count;
367 default: 367 default:
368 return 0; 368 return 0;
369 } 369 }
370 } 370 }
371 371
372 #pragma mark - UIPickerViewDelegate 372 #pragma mark - UIPickerViewDelegate
373 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 373 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
374 { 374 {
375 int tag = (int)pickerView.tag; 375 int tag = (int)pickerView.tag;
376 switch (tag) { 376 switch (tag) {
377 case kPickerTagArea: 377 case kPickerTagArea:
378 _tfArea.text = [_arrayArea objectAtIndex:row]; 378 _tfArea.text = [_arrayArea objectAtIndex:row];
379 break; 379 break;
380 case kPickerTagSex: 380 case kPickerTagSex:
381 _tflblSex.text = [_arraySex objectAtIndex:row]; 381 _tflblSex.text = [_arraySex objectAtIndex:row];
382 break; 382 break;
383 default: 383 default:
384 break; 384 break;
385 } 385 }
386 } 386 }
387 387
388 - (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component 388 - (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
389 { 389 {
390 NSString *strTitle = @""; 390 NSString *strTitle = @"";
391 int tag = (int)pickerView.tag; 391 int tag = (int)pickerView.tag;
392 switch (tag) { 392 switch (tag) {
393 case kPickerTagArea: 393 case kPickerTagArea:
394 strTitle = [_arrayArea objectAtIndex:row]; 394 strTitle = [_arrayArea objectAtIndex:row];
395 break; 395 break;
396 case kPickerTagSex: 396 case kPickerTagSex:
397 strTitle = [_arraySex objectAtIndex:row]; 397 strTitle = [_arraySex objectAtIndex:row];
398 break; 398 break;
399 default: 399 default:
400 strTitle = @""; 400 strTitle = @"";
401 break; 401 break;
402 } 402 }
403 NSAttributedString *attString = [[NSAttributedString alloc] initWithString:strTitle attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; 403 NSAttributedString *attString = [[NSAttributedString alloc] initWithString:strTitle attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
404 404
405 return attString; 405 return attString;
406 406
407 } 407 }
408 408
409 - (NSMutableDictionary *)addParam:(NSString *)param value:(NSString *)value withDict:(NSMutableDictionary *)dict 409 - (NSMutableDictionary *)addParam:(NSString *)param value:(NSString *)value withDict:(NSMutableDictionary *)dict
410 { 410 {
411 if (value.length > 0) { 411 if (value.length > 0) {
412 [dict setObject:value forKey:param]; 412 [dict setObject:value forKey:param];
413 } 413 }
414 return dict; 414 return dict;
415 } 415 }
416 416
417 - (BOOL)checkAllowRegister 417 - (BOOL)checkAllowRegister
418 { 418 {
419 NSString *message = @""; 419 NSString *message = @"";
420 if (_tfUsername.text.length <= 0) { 420 if (_tfUsername.text.length <= 0) {
421 message = @"Please input username"; 421 message = @"Please input username";
422 [Utilities showErrorMessage:message withViewController:self]; 422 [Utilities showErrorMessage:message withViewController:self];
423 return NO; 423 return NO;
424 } 424 }
425 if (_tfName.text.length <= 0) { 425 if (_tfName.text.length <= 0) {
426 message = @"Please input full name"; 426 message = @"Please input full name";
427 [Utilities showErrorMessage:message withViewController:self]; 427 [Utilities showErrorMessage:message withViewController:self];
428 return NO; 428 return NO;
429 } 429 }
430 if (_tfEmail.text.length <= 0) { 430 if (_tfEmail.text.length <= 0) {
431 message = @"Please input email"; 431 message = @"Please input email";
432 [Utilities showErrorMessage:message withViewController:self]; 432 [Utilities showErrorMessage:message withViewController:self];
433 return NO; 433 return NO;
434 } 434 }
435 if (_tfPassword.text.length <= 0) { 435 if (_tfPassword.text.length <= 0) {
436 message = @"Please input password"; 436 message = @"Please input password";
437 [Utilities showErrorMessage:message withViewController:self]; 437 [Utilities showErrorMessage:message withViewController:self];
438 return NO; 438 return NO;
439 } 439 }
440 if (_tfConfirmPassword.text.length <= 0) { 440 if (_tfConfirmPassword.text.length <= 0) {
441 message = @"Please input confirm password"; 441 message = @"Please input confirm password";
442 [Utilities showErrorMessage:message withViewController:self]; 442 [Utilities showErrorMessage:message withViewController:self];
443 return NO; 443 return NO;
444 } 444 }
445 if (_tflblSex.text.length <= 0) { 445 if (_tflblSex.text.length <= 0) {
446 message = @"Please input gender"; 446 message = @"Please input gender";
447 [Utilities showErrorMessage:message withViewController:self]; 447 [Utilities showErrorMessage:message withViewController:self];
448 return NO; 448 return NO;
449 } 449 }
450 if (_tfUsername.text.length > 100) { 450 if (_tfUsername.text.length > 100) {
451 message = @"Username maximum length 100"; 451 message = @"Username maximum length 100";
452 [Utilities showErrorMessage:message withViewController:self]; 452 [Utilities showErrorMessage:message withViewController:self];
453 return NO; 453 return NO;
454 } 454 }
455 if (_tfName.text.length > 255) { 455 if (_tfName.text.length > 255) {
456 message = @"Full name maximum length 255"; 456 message = @"Full name maximum length 255";
457 [Utilities showErrorMessage:message withViewController:self]; 457 [Utilities showErrorMessage:message withViewController:self];
458 return NO; 458 return NO;
459 } 459 }
460 if (_tfEmail.text.length > 255) { 460 if (_tfEmail.text.length > 255) {
461 message = @"Email maximum length 255"; 461 message = @"Email maximum length 255";
462 [Utilities showErrorMessage:message withViewController:self]; 462 [Utilities showErrorMessage:message withViewController:self];
463 return NO; 463 return NO;
464 } 464 }
465 if (_tfPassword.text.length < 6) { 465 if (_tfPassword.text.length < 6) {
466 message = @"Password minimum length 6"; 466 message = @"Password minimum length 6";
467 [Utilities showErrorMessage:message withViewController:self]; 467 [Utilities showErrorMessage:message withViewController:self];
468 return NO; 468 return NO;
469 } 469 }
470 if (![_tfEmail.text containsString:@"@"]) { 470 if (![_tfEmail.text containsString:@"@"]) {
471 message = @"Email invalid"; 471 message = @"Email invalid";
472 [Utilities showErrorMessage:message withViewController:self]; 472 [Utilities showErrorMessage:message withViewController:self];
473 return NO; 473 return NO;
474 } 474 }
475 return YES; 475 return YES;
476 } 476 }
477 477
478 - (NSDictionary *)createParamsForRegisterUser { 478 - (NSDictionary *)createParamsForRegisterUser {
479 NSMutableDictionary *dictResutl = [[NSMutableDictionary alloc] init]; 479 NSMutableDictionary *dictResutl = [[NSMutableDictionary alloc] init];
480 dictResutl = [self addParam:@"username" value:_tfUsername.text withDict:dictResutl]; 480 dictResutl = [self addParam:@"username" value:_tfUsername.text withDict:dictResutl];
481 dictResutl = [self addParam:@"full_name" value:_tfName.text withDict:dictResutl]; 481 dictResutl = [self addParam:@"full_name" value:_tfName.text withDict:dictResutl];
482 dictResutl = [self addParam:@"nickname" value:_tfNickname.text withDict:dictResutl]; 482 dictResutl = [self addParam:@"nickname" value:_tfNickname.text withDict:dictResutl];
483 dictResutl = [self addParam:@"email" value:_tfEmail.text withDict:dictResutl]; 483 dictResutl = [self addParam:@"email" value:_tfEmail.text withDict:dictResutl];
484 dictResutl = [self addParam:@"password" value:_tfPassword.text withDict:dictResutl]; 484 dictResutl = [self addParam:@"password" value:_tfPassword.text withDict:dictResutl];
485 dictResutl = [self addParam:@"password_confirmation" value:_tfConfirmPassword.text withDict:dictResutl]; 485 dictResutl = [self addParam:@"password_confirmation" value:_tfConfirmPassword.text withDict:dictResutl];
486 // 0 - 男, 1 - 女 // NSString *valueSex = nil; 486 // 0 - 男, 1 - 女 // NSString *valueSex = nil;
487 if (_tflblSex.text.length > 0) { 487 if (_tflblSex.text.length > 0) {
488 if ([_tflblSex.text isEqualToString:@"男"]) { 488 if ([_tflblSex.text isEqualToString:@"男"]) {
489 [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"gender"]; 489 [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"gender"];
490 } 490 }
491 else if ([_tflblSex.text isEqualToString:@"女"]) { 491 else if ([_tflblSex.text isEqualToString:@"女"]) {
492 [dictResutl setValue:[NSNumber numberWithInt:1] forKey:@"gender"]; 492 [dictResutl setValue:[NSNumber numberWithInt:1] forKey:@"gender"];
493 } 493 }
494 } 494 }
495 //dictResutl = [self addParam:@"gender" value:valueSex withDict:dictResutl]; 495 //dictResutl = [self addParam:@"gender" value:valueSex withDict:dictResutl];
496 NSString *valueBirthDay = nil; 496 NSString *valueBirthDay = nil;
497 if (_tfBirthday.text.length > 0) { 497 if (_tfBirthday.text.length > 0) {
498 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 498 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
499 [dateFormatter setDateFormat:@"yyyy-MM-dd"]; 499 [dateFormatter setDateFormat:@"yyyy-MM-dd"];
500 valueBirthDay = [dateFormatter stringFromDate:dateBirthDay]; 500 valueBirthDay = [dateFormatter stringFromDate:dateBirthDay];
501 //valueBirthDay = [NSString stringWithFormat:@"%ld-%ld-%ld", (long)[dateBirthDay getYear], (long)[dateBirthDay getMonth], (long)[dateBirthDay getDay]]; 501 //valueBirthDay = [NSString stringWithFormat:@"%ld-%ld-%ld", (long)[dateBirthDay getYear], (long)[dateBirthDay getMonth], (long)[dateBirthDay getDay]];
502 dictResutl = [self addParam:@"birthday" value:valueBirthDay withDict:dictResutl]; 502 dictResutl = [self addParam:@"birthday" value:valueBirthDay withDict:dictResutl];
503 } 503 }
504 dictResutl = [self addParam:@"height" value:_tfHeight.text withDict:dictResutl]; 504 dictResutl = [self addParam:@"height" value:_tfHeight.text withDict:dictResutl];
505 dictResutl = [self addParam:@"weight" value:_tfWeight.text withDict:dictResutl]; 505 dictResutl = [self addParam:@"weight" value:_tfWeight.text withDict:dictResutl];
506 dictResutl = [self addParam:@"fat_rate" value:_tfFatPercentage.text withDict:dictResutl]; 506 dictResutl = [self addParam:@"fat_rate" value:_tfFatPercentage.text withDict:dictResutl];
507 NSString *physicalActivityValue = [NSString stringWithFormat:@"%ld", _physicalActivity.selectedSegmentIndex]; 507 NSString *physicalActivityValue = [NSString stringWithFormat:@"%ld", _physicalActivity.selectedSegmentIndex];
508 dictResutl = [self addParam:@"physical_activity" value:physicalActivityValue withDict:dictResutl]; 508 dictResutl = [self addParam:@"physical_activity" value:physicalActivityValue withDict:dictResutl];
509 dictResutl = [self addParam:@"address" value:_tfArea.text withDict:dictResutl]; 509 dictResutl = [self addParam:@"address" value:_tfArea.text withDict:dictResutl];
510 dictResutl = [self addParam:@"description" value:_tvNote.text withDict:dictResutl]; 510 dictResutl = [self addParam:@"description" value:_tvNote.text withDict:dictResutl];
511 if (![profile_image isEqualToString:@""]) { 511 if (![profile_image isEqualToString:@""]) {
512 dictResutl = [self addParam:@"profile_image" value:profile_image withDict:dictResutl]; 512 dictResutl = [self addParam:@"profile_image" value:profile_image withDict:dictResutl];
513 } 513 }
514 // hardcode 514 // hardcode
515 // require 515 // require
516 [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"receive_notification"]; 516 [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"receive_notification"];
517 // = [self addParam:@"receive_notification" value:@"0" withDict:dictResutl]; 517 // = [self addParam:@"receive_notification" value:@"0" withDict:dictResutl];
518 [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"share_data"]; 518 [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"share_data"];
519 // dictResutl = [self addParam:@"share_data" value:@"0" withDict:dictResutl]; 519 // dictResutl = [self addParam:@"share_data" value:@"0" withDict:dictResutl];
520 520
521 // Option 521 // Option
522 //dictResutl = [self addParam:@"phone" value:@"01676582596" withDict:dictResutl]; 522 //dictResutl = [self addParam:@"phone" value:@"01676582596" withDict:dictResutl];
523 [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"remember"]; 523 [dictResutl setValue:[NSNumber numberWithInt:0] forKey:@"remember_me"];
524 //dictResutl = [self addParam:@"remember" value:@"0" withDict:dictResutl]; 524 //dictResutl = [self addParam:@"remember" value:@"0" withDict:dictResutl];
525 525
526 return dictResutl; 526 return dictResutl;
527 } 527 }
528 528
529 - (void)registerUser { 529 - (void)registerUser {
530 NSDictionary *paramRegister = [self createParamsForRegisterUser]; 530 NSDictionary *paramRegister = [self createParamsForRegisterUser];
531 RegisterViewController __weak *weakSelf = self; 531 RegisterViewController __weak *weakSelf = self;
532 [[ServerAPI server] registerUserWithParams:paramRegister CompletionHandler:^(User *user, NSString *token, NSError *error) { 532 [[ServerAPI server] registerUserWithParams:paramRegister CompletionHandler:^(User *user, NSString *token, NSError *error) {
533 if (weakSelf == nil) { 533 if (weakSelf == nil) {
534 return ; 534 return ;
535 } 535 }
536 if (error == nil) { 536 if (error == nil) {
537 // For Saving 537 // For Saving
538 NSData *dataSave = [NSKeyedArchiver archivedDataWithRootObject:user]; 538 NSData *dataSave = [NSKeyedArchiver archivedDataWithRootObject:user];
539 [[NSUserDefaults standardUserDefaults] setObject:dataSave forKey:kUser]; 539 [[NSUserDefaults standardUserDefaults] setObject:dataSave forKey:kUser];
540 [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; 540 [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken];
541 [[NSUserDefaults standardUserDefaults] synchronize]; 541 [[NSUserDefaults standardUserDefaults] synchronize];
542 dispatch_async(dispatch_get_main_queue(), ^{ 542 dispatch_async(dispatch_get_main_queue(), ^{
543 [[AppDelegate sharedAppDelegate] gotoMainMenu]; 543 [[AppDelegate sharedAppDelegate] gotoMainMenu];
544 }); 544 });
545 } 545 }
546 else { 546 else {
547 dispatch_async(dispatch_get_main_queue(), ^{ 547 dispatch_async(dispatch_get_main_queue(), ^{
548 NSString *message = [error.userInfo objectForKey:@"message"]; 548 NSString *message = [error.userInfo objectForKey:@"message"];
549 [Utilities showErrorMessage:message withViewController:weakSelf]; 549 [Utilities showErrorMessage:message withViewController:weakSelf];
550 }); 550 });
551 } 551 }
552 }]; 552 }];
553 } 553 }
554 554
555 @end 555 @end
556 556