Commit 3c805063b5b987fbb80f35b76673c9d33c2ab091
1 parent
26548f2f08
Exists in
master
update api notice
Showing 5 changed files with 97 additions and 19 deletions Inline Diff
LifeLog/LifeLog/HomeViewConb troller.m
1 | // | 1 | // |
2 | // HomeViewController.m | 2 | // HomeViewController.m |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by Nguyen Van Phong on 7/25/17. | 5 | // Created by Nguyen Van Phong on 7/25/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import "HomeViewController.h" | 9 | #import "HomeViewController.h" |
10 | #import "NSDate+helper.h" | 10 | #import "NSDate+helper.h" |
11 | #import <CoreMotion/CoreMotion.h> | 11 | #import <CoreMotion/CoreMotion.h> |
12 | #import "CMMotionActivityExtra.h" | 12 | #import "CMMotionActivityExtra.h" |
13 | #import "TodayViewController.h" | 13 | #import "TodayViewController.h" |
14 | #import "Utilities.h" | 14 | #import "Utilities.h" |
15 | #import <MBProgressHUD/MBProgressHUD.h> | 15 | #import <MBProgressHUD/MBProgressHUD.h> |
16 | #import "ServerAPI.h" | 16 | #import "ServerAPI.h" |
17 | 17 | ||
18 | static NSInteger maxRequest = 20; | 18 | static NSInteger maxRequest = 20; |
19 | static NSInteger numberTotal = 10000; | 19 | static NSInteger numberTotal = 10000; |
20 | 20 | ||
21 | @interface HomeViewController () | 21 | @interface HomeViewController () |
22 | { | 22 | { |
23 | MBProgressHUD *progressHud; | 23 | MBProgressHUD *progressHud; |
24 | NSInteger targetStep; | 24 | NSInteger targetStep; |
25 | } | 25 | } |
26 | @property (nonatomic, weak) IBOutlet UILabel *lblTitle; | 26 | @property (nonatomic, weak) IBOutlet UILabel *lblTitle; |
27 | @property (nonatomic, weak) IBOutlet UIImageView *avatar; | 27 | @property (nonatomic, weak) IBOutlet UIImageView *avatar; |
28 | @property (nonatomic, weak) IBOutlet UILabel *lblDateCurrent; | 28 | @property (nonatomic, weak) IBOutlet UILabel *lblDateCurrent; |
29 | @property (nonatomic, weak) IBOutlet UILabel *lblValueStep; | 29 | @property (nonatomic, weak) IBOutlet UILabel *lblValueStep; |
30 | @property (nonatomic, weak) IBOutlet UILabel *lblUnitStep; | 30 | @property (nonatomic, weak) IBOutlet UILabel *lblUnitStep; |
31 | @property (nonatomic, weak) IBOutlet UILabel *lblValueStepOther; | 31 | @property (nonatomic, weak) IBOutlet UILabel *lblValueStepOther; |
32 | @property (nonatomic, weak) IBOutlet UILabel *lblPercent; | 32 | @property (nonatomic, weak) IBOutlet UILabel *lblPercent; |
33 | @property (nonatomic, weak) IBOutlet UILabel *lblNotice; | 33 | @property (nonatomic, weak) IBOutlet UILabel *lblNotice; |
34 | @property (weak, nonatomic) IBOutlet UISegmentedControl *segmentHome; | 34 | @property (weak, nonatomic) IBOutlet UISegmentedControl *segmentHome; |
35 | @property (weak, nonatomic) IBOutlet UITextView *tvNotice; | 35 | @property (weak, nonatomic) IBOutlet UITextView *tvNotice; |
36 | 36 | ||
37 | @property (nonatomic, strong) CMPedometer *pedometer; | 37 | @property (nonatomic, strong) CMPedometer *pedometer; |
38 | @property (nonatomic, strong) CMMotionActivityManager *motionActivityManager; | 38 | @property (nonatomic, strong) CMMotionActivityManager *motionActivityManager; |
39 | @property (nonatomic, strong) NSOperationQueue *operationQueue; | 39 | @property (nonatomic, strong) NSOperationQueue *operationQueue; |
40 | @property (nonatomic, strong) NSTimer *timer; | 40 | @property (nonatomic, strong) NSTimer *timer; |
41 | @property (nonatomic, assign) NSInteger bike; | 41 | @property (nonatomic, assign) NSInteger bike; |
42 | @property (nonatomic, assign) NSInteger walking; | 42 | @property (nonatomic, assign) NSInteger walking; |
43 | @property (nonatomic, assign) NSInteger running; | 43 | @property (nonatomic, assign) NSInteger running; |
44 | @property (nonatomic, strong) NSDate *dateCurrent; | 44 | @property (nonatomic, strong) NSDate *dateCurrent; |
45 | 45 | ||
46 | @property (nonatomic, assign) int totalRequest; | 46 | @property (nonatomic, assign) int totalRequest; |
47 | @property (nonatomic, assign) int countComplete; | 47 | @property (nonatomic, assign) int countComplete; |
48 | @property (nonatomic, assign) int currentIndex; | 48 | @property (nonatomic, assign) int currentIndex; |
49 | 49 | ||
50 | @end | 50 | @end |
51 | 51 | ||
52 | @implementation HomeViewController | 52 | @implementation HomeViewController |
53 | 53 | ||
54 | - (void)viewDidLoad { | 54 | - (void)viewDidLoad { |
55 | [super viewDidLoad]; | 55 | [super viewDidLoad]; |
56 | 56 | ||
57 | self.lblTitle.text = NSLocalizedString(@"lifelog.home.title", nil); | 57 | self.lblTitle.text = NSLocalizedString(@"lifelog.home.title", nil); |
58 | 58 | ||
59 | [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.lblTitle attribute:NSLayoutAttributeTop multiplier:1 constant:0]]; | 59 | [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.lblTitle attribute:NSLayoutAttributeTop multiplier:1 constant:0]]; |
60 | 60 | ||
61 | self.avatar.backgroundColor = [UIColor whiteColor]; | 61 | self.avatar.backgroundColor = [UIColor whiteColor]; |
62 | self.avatar.layer.borderWidth = 2.0f; | 62 | self.avatar.layer.borderWidth = 2.0f; |
63 | self.avatar.layer.borderColor = [[UIColor whiteColor] CGColor]; | 63 | self.avatar.layer.borderColor = [[UIColor whiteColor] CGColor]; |
64 | self.avatar.layer.cornerRadius = self.avatar.frame.size.width/2.0f; | 64 | self.avatar.layer.cornerRadius = self.avatar.frame.size.width/2.0f; |
65 | self.avatar.layer.masksToBounds = YES; | 65 | self.avatar.layer.masksToBounds = YES; |
66 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; | 66 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; |
67 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; | 67 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; |
68 | if (user != nil) { | 68 | if (user != nil) { |
69 | NSString *linkImage = [NSString stringWithFormat:@"%@%@", kServerAddress, user.profile_image]; | 69 | NSString *linkImage = [NSString stringWithFormat:@"%@%@", kServerAddress, user.profile_image]; |
70 | NSURL *urlImage = [NSURL URLWithString:linkImage]; | 70 | NSURL *urlImage = [NSURL URLWithString:linkImage]; |
71 | NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; | 71 | NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; |
72 | sessionConfig.timeoutIntervalForRequest = 30.0; | 72 | sessionConfig.timeoutIntervalForRequest = 30.0; |
73 | sessionConfig.timeoutIntervalForResource = 60.0; | 73 | sessionConfig.timeoutIntervalForResource = 60.0; |
74 | sessionConfig.HTTPMaximumConnectionsPerHost = 20; | 74 | sessionConfig.HTTPMaximumConnectionsPerHost = 20; |
75 | sessionConfig.allowsCellularAccess = YES; | 75 | sessionConfig.allowsCellularAccess = YES; |
76 | HomeViewController __weak *weakSelf = self; | 76 | HomeViewController __weak *weakSelf = self; |
77 | NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig]; | 77 | NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig]; |
78 | NSURLSessionDataTask *downloadPhotoTask = [session | 78 | NSURLSessionDataTask *downloadPhotoTask = [session |
79 | dataTaskWithURL:urlImage completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { | 79 | dataTaskWithURL:urlImage completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { |
80 | if (weakSelf == nil) | 80 | if (weakSelf == nil) |
81 | { | 81 | { |
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | if (error == nil) { | 84 | if (error == nil) { |
85 | UIImage *image = [[UIImage alloc] initWithData:data]; | 85 | UIImage *image = [[UIImage alloc] initWithData:data]; |
86 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | 86 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
87 | weakSelf.avatar.image = image; | 87 | weakSelf.avatar.image = image; |
88 | }]; | 88 | }]; |
89 | } | 89 | } |
90 | }]; | 90 | }]; |
91 | [downloadPhotoTask resume]; | 91 | [downloadPhotoTask resume]; |
92 | } | 92 | } |
93 | 93 | ||
94 | self.lblNotice.text = NSLocalizedString(@"lifelog.home.notice", nil); | 94 | self.lblNotice.text = NSLocalizedString(@"lifelog.home.notice", nil); |
95 | 95 | ||
96 | _dateCurrent = [NSDate date]; | 96 | _dateCurrent = [NSDate date]; |
97 | self.lblDateCurrent.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[_dateCurrent getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[_dateCurrent getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[_dateCurrent getDay], NSLocalizedString(@"lifelog.common.day", nil)]; | 97 | self.lblDateCurrent.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[_dateCurrent getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[_dateCurrent getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[_dateCurrent getDay], NSLocalizedString(@"lifelog.common.day", nil)]; |
98 | 98 | ||
99 | self.lblUnitStep.text = NSLocalizedString(@"lifelog.home.unit.step", nil); | 99 | self.lblUnitStep.text = NSLocalizedString(@"lifelog.home.unit.step", nil); |
100 | 100 | ||
101 | if ([CMPedometer isStepCountingAvailable]) { | 101 | if ([CMPedometer isStepCountingAvailable]) { |
102 | _pedometer = [[CMPedometer alloc] init]; | 102 | _pedometer = [[CMPedometer alloc] init]; |
103 | } | 103 | } |
104 | if ([CMMotionActivityManager isActivityAvailable]) { | 104 | if ([CMMotionActivityManager isActivityAvailable]) { |
105 | _motionActivityManager = [[CMMotionActivityManager alloc] init]; | 105 | _motionActivityManager = [[CMMotionActivityManager alloc] init]; |
106 | } | 106 | } |
107 | _operationQueue = [[NSOperationQueue alloc] init]; | 107 | _operationQueue = [[NSOperationQueue alloc] init]; |
108 | _bike = 0; | 108 | _bike = 0; |
109 | _walking = 0; | 109 | _walking = 0; |
110 | _running = 0; | 110 | _running = 0; |
111 | _segmentHome.selectedSegmentIndex = 1; | 111 | _segmentHome.selectedSegmentIndex = 1; |
112 | _totalRequest = 0; | 112 | _totalRequest = 0; |
113 | _countComplete = 0; | 113 | _countComplete = 0; |
114 | 114 | ||
115 | progressHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; | 115 | progressHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; |
116 | progressHud.mode = MBProgressHUDModeIndeterminate; | 116 | progressHud.mode = MBProgressHUDModeIndeterminate; |
117 | progressHud.detailsLabel.text = NSLocalizedString(@"lifelog.home.progressHud.title", nil); | 117 | progressHud.detailsLabel.text = NSLocalizedString(@"lifelog.home.progressHud.title", nil); |
118 | // [self saveDataStep7LastDay]; | 118 | // [self saveDataStep7LastDay]; |
119 | targetStep = numberTotal; | 119 | targetStep = numberTotal; |
120 | [self requestNotice]; | ||
120 | } | 121 | } |
121 | 122 | ||
123 | - (void)requestNotice | ||
124 | { | ||
125 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | ||
126 | [dateFormatter setDateFormat:@"yyyy-MM-dd"]; | ||
127 | NSString *dateString = [dateFormatter stringFromDate:_dateCurrent]; | ||
128 | HomeViewController __weak *weakSelf = self; | ||
129 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
130 | //Do background work | ||
131 | [[ServerAPI server] getNoticeByDate:dateString CompletionHandler:^(NSArray *arrResults, NSError *error) { | ||
132 | if(weakSelf == nil) { | ||
133 | return ; | ||
134 | } | ||
135 | if (error == nil) { | ||
136 | // NSLog(@"List Notices: %@", arrResults); | ||
137 | dispatch_async(dispatch_get_main_queue(), ^{ | ||
138 | NSString *stringNotice = @""; | ||
139 | for (NSString *noticeInfor in arrResults) { | ||
140 | NSString *noticeString = [NSString stringWithFormat:@"%@\n", noticeInfor]; | ||
141 | stringNotice = [stringNotice stringByAppendingString:noticeString]; | ||
142 | } | ||
143 | weakSelf.tvNotice.text = stringNotice; | ||
144 | }); | ||
145 | } | ||
146 | else { | ||
147 | dispatch_async(dispatch_get_main_queue(), ^{ | ||
148 | weakSelf.tvNotice.text = @""; | ||
149 | /* | ||
150 | NSString *message = [error.userInfo objectForKey:@"message"]; | ||
151 | [Utilities showErrorMessage:message withViewController:weakSelf]; | ||
152 | */ | ||
153 | }); | ||
154 | } | ||
155 | }]; | ||
156 | }); | ||
157 | } | ||
158 | |||
122 | - (void)viewWillAppear:(BOOL)animated { | 159 | - (void)viewWillAppear:(BOOL)animated { |
123 | [super viewWillAppear:animated]; | 160 | [super viewWillAppear:animated]; |
124 | NSDate *dateNow = [NSDate date]; | 161 | NSDate *dateNow = [NSDate date]; |
125 | [self saveStepForDay:dateNow]; | 162 | [self saveStepForDay:dateNow]; |
126 | } | 163 | } |
127 | 164 | ||
128 | - (void)requestTopByDate:(NSDate *)date { | 165 | - (void)requestTopByDate:(NSDate *)date { |
129 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | 166 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
130 | [dateFormatter setDateFormat:@"yyyy-MM-dd"]; | 167 | [dateFormatter setDateFormat:@"yyyy-MM-dd"]; |
131 | NSString *dateString = [dateFormatter stringFromDate:date]; | 168 | NSString *dateString = [dateFormatter stringFromDate:date]; |
132 | [progressHud showAnimated:YES]; | 169 | [progressHud showAnimated:YES]; |
133 | [progressHud setHidden:NO]; | 170 | [progressHud setHidden:NO]; |
134 | HomeViewController __weak *weakSelf = self; | 171 | HomeViewController __weak *weakSelf = self; |
135 | int mode = 1; | 172 | int mode = 1; |
136 | switch (_segmentHome.selectedSegmentIndex) { | 173 | switch (_segmentHome.selectedSegmentIndex) { |
137 | case 0: | 174 | case 0: |
138 | mode = 3; | 175 | mode = 3; |
139 | break; | 176 | break; |
140 | 177 | ||
141 | case 1: | 178 | case 1: |
142 | mode = 1; | 179 | mode = 1; |
143 | break; | 180 | break; |
144 | 181 | ||
145 | case 2: | 182 | case 2: |
146 | mode = 2; | 183 | mode = 2; |
147 | break; | 184 | break; |
148 | 185 | ||
149 | default: | 186 | default: |
150 | break; | 187 | break; |
151 | } | 188 | } |
152 | [[ServerAPI server] requestTopWithMode:mode andDate:dateString CompletionHandler:^(TopObject *topObject, NSError *error) { | 189 | [[ServerAPI server] requestTopWithMode:mode andDate:dateString CompletionHandler:^(TopObject *topObject, NSError *error) { |
153 | if(weakSelf == nil) { | 190 | if(weakSelf == nil) { |
154 | return ; | 191 | return ; |
155 | } | 192 | } |
156 | if (error == nil) { | 193 | if (error == nil) { |
157 | NSLog(@"TopObject: %@", topObject); | 194 | NSLog(@"TopObject: %@", topObject); |
158 | dispatch_async(dispatch_get_main_queue(), ^{ | 195 | dispatch_async(dispatch_get_main_queue(), ^{ |
159 | [weakSelf updateStepUI:topObject.targetInfor]; | 196 | [weakSelf updateStepUI:topObject.targetInfor]; |
160 | }); | 197 | }); |
161 | } | 198 | } |
162 | else { | 199 | else { |
163 | dispatch_async(dispatch_get_main_queue(), ^{ | 200 | dispatch_async(dispatch_get_main_queue(), ^{ |
164 | NSString *message = [error.userInfo objectForKey:@"message"]; | 201 | NSString *message = [error.userInfo objectForKey:@"message"]; |
165 | [Utilities showErrorMessage:message withViewController:weakSelf]; | 202 | [Utilities showErrorMessage:message withViewController:weakSelf]; |
166 | }); | 203 | }); |
167 | } | 204 | } |
168 | dispatch_async(dispatch_get_main_queue(), ^{ | 205 | dispatch_async(dispatch_get_main_queue(), ^{ |
169 | [progressHud setHidden:YES]; | 206 | [progressHud setHidden:YES]; |
170 | }); | 207 | }); |
171 | }]; | 208 | }]; |
209 | /* | ||
172 | [[ServerAPI server] requestHomeWithMode:mode andDate:dateString CompletionHandler:^(HomeObject *homeObject, NSError *error) { | 210 | [[ServerAPI server] requestHomeWithMode:mode andDate:dateString CompletionHandler:^(HomeObject *homeObject, NSError *error) { |
173 | if(weakSelf == nil) { | 211 | if(weakSelf == nil) { |
174 | return ; | 212 | return ; |
175 | } | 213 | } |
176 | if (error == nil) { | 214 | if (error == nil) { |
177 | NSLog(@"List Notices: %@", homeObject.listNotice); | 215 | NSLog(@"List Notices: %@", homeObject.listNotice); |
178 | for (NoticeInfor *noticeInfor in homeObject.listNotice) { | 216 | for (NoticeInfor *noticeInfor in homeObject.listNotice) { |
179 | NSLog(@"noticeInfor: %@", noticeInfor.notice_content); | 217 | NSLog(@"noticeInfor: %@", noticeInfor.notice_content); |
180 | } | 218 | } |
181 | dispatch_async(dispatch_get_main_queue(), ^{ | 219 | dispatch_async(dispatch_get_main_queue(), ^{ |
182 | [weakSelf updateNoticeUI:homeObject]; | 220 | [weakSelf updateNoticeUI:homeObject]; |
183 | }); | 221 | }); |
184 | } | 222 | } |
185 | else { | 223 | else { |
186 | dispatch_async(dispatch_get_main_queue(), ^{ | 224 | dispatch_async(dispatch_get_main_queue(), ^{ |
187 | NSString *message = [error.userInfo objectForKey:@"message"]; | 225 | NSString *message = [error.userInfo objectForKey:@"message"]; |
188 | [Utilities showErrorMessage:message withViewController:weakSelf]; | 226 | [Utilities showErrorMessage:message withViewController:weakSelf]; |
189 | }); | 227 | }); |
190 | } | 228 | } |
191 | dispatch_async(dispatch_get_main_queue(), ^{ | 229 | dispatch_async(dispatch_get_main_queue(), ^{ |
192 | [progressHud setHidden:YES]; | 230 | [progressHud setHidden:YES]; |
193 | }); | 231 | }); |
194 | }]; | 232 | }]; |
233 | */ | ||
195 | } | 234 | } |
196 | 235 | ||
197 | - (void)viewWillDisappear:(BOOL)animated { | 236 | - (void)viewWillDisappear:(BOOL)animated { |
198 | [super viewWillDisappear:animated]; | 237 | [super viewWillDisappear:animated]; |
199 | } | 238 | } |
200 | 239 | ||
201 | - (void)didReceiveMemoryWarning { | 240 | - (void)didReceiveMemoryWarning { |
202 | [super didReceiveMemoryWarning]; | 241 | [super didReceiveMemoryWarning]; |
203 | // Dispose of any resources that can be recreated. | 242 | // Dispose of any resources that can be recreated. |
204 | } | 243 | } |
205 | 244 | ||
206 | #pragma mark - IBAction | 245 | #pragma mark - IBAction |
207 | - (IBAction)menuButtonTouchUpInside:(id)sender | 246 | - (IBAction)menuButtonTouchUpInside:(id)sender |
208 | { | 247 | { |
209 | 248 | ||
210 | } | 249 | } |
211 | 250 | ||
212 | - (IBAction)todayButtonTouchUpInside:(id)sender | 251 | - (IBAction)todayButtonTouchUpInside:(id)sender |
213 | { | 252 | { |
214 | TodayViewController *todayVC = [[TodayViewController alloc] initWithNibName:@"TodayViewController" bundle:nil]; | 253 | TodayViewController *todayVC = [[TodayViewController alloc] initWithNibName:@"TodayViewController" bundle:nil]; |
215 | todayVC.targetStep = targetStep; | 254 | todayVC.targetStep = targetStep; |
216 | [self.navigationController pushViewController:todayVC animated:YES]; | 255 | [self.navigationController pushViewController:todayVC animated:YES]; |
217 | } | 256 | } |
218 | 257 | ||
219 | - (IBAction)leftButtonTouchUpInside:(id)sender | 258 | - (IBAction)leftButtonTouchUpInside:(id)sender |
220 | { | 259 | { |
221 | self.dateCurrent = [self.dateCurrent dateByAddingTimeInterval:-(24*60*60)]; | 260 | self.dateCurrent = [self.dateCurrent dateByAddingTimeInterval:-(24*60*60)]; |
222 | self.lblDateCurrent.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[_dateCurrent getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[_dateCurrent getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[_dateCurrent getDay], NSLocalizedString(@"lifelog.common.day", nil)]; | 261 | self.lblDateCurrent.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[_dateCurrent getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[_dateCurrent getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[_dateCurrent getDay], NSLocalizedString(@"lifelog.common.day", nil)]; |
223 | [self resetStepUI]; | 262 | [self resetStepUI]; |
224 | [self saveStepForDay:self.dateCurrent]; | 263 | [self saveStepForDay:self.dateCurrent]; |
264 | [self requestNotice]; | ||
225 | } | 265 | } |
226 | 266 | ||
227 | - (IBAction)rightButtonTouchUpInside:(id)sender | 267 | - (IBAction)rightButtonTouchUpInside:(id)sender |
228 | { | 268 | { |
229 | self.dateCurrent = [self.dateCurrent dateByAddingTimeInterval:24*60*60]; | 269 | self.dateCurrent = [self.dateCurrent dateByAddingTimeInterval:24*60*60]; |
230 | self.lblDateCurrent.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[_dateCurrent getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[_dateCurrent getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[_dateCurrent getDay], NSLocalizedString(@"lifelog.common.day", nil)]; | 270 | self.lblDateCurrent.text = [NSString stringWithFormat:@"%ld%@%ld%@%ld%@", (long)[_dateCurrent getYear], NSLocalizedString(@"lifelog.common.year", nil), (long)[_dateCurrent getMonth], NSLocalizedString(@"lifelog.common.month", nil), (long)[_dateCurrent getDay], NSLocalizedString(@"lifelog.common.day", nil)]; |
231 | [self resetStepUI]; | 271 | [self resetStepUI]; |
232 | //[self saveStepForDay:self.dateCurrent]; | 272 | //[self saveStepForDay:self.dateCurrent]; |
233 | [self requestTopByDate:self.dateCurrent]; | 273 | [self requestTopByDate:self.dateCurrent]; |
274 | [self requestNotice]; | ||
234 | } | 275 | } |
235 | 276 | ||
236 | - (IBAction)segmentValueChange:(id)sender { | 277 | - (IBAction)segmentValueChange:(id)sender { |
237 | [self resetStepUI]; | 278 | [self resetStepUI]; |
238 | [self requestTopByDate:self.dateCurrent]; | 279 | [self requestTopByDate:self.dateCurrent]; |
239 | } | 280 | } |
240 | 281 | ||
241 | #pragma mark - Functions Private | 282 | #pragma mark - Functions Private |
242 | - (void)saveStepForDay:(NSDate *)date | 283 | - (void)saveStepForDay:(NSDate *)date |
243 | { | 284 | { |
244 | if ([CMMotionActivityManager isActivityAvailable]) { | 285 | if ([CMMotionActivityManager isActivityAvailable]) { |
245 | [progressHud showAnimated:YES]; | 286 | [progressHud showAnimated:YES]; |
246 | [progressHud setHidden:NO]; | 287 | [progressHud setHidden:NO]; |
247 | self.bike = 0; | 288 | self.bike = 0; |
248 | self.walking = 0; | 289 | self.walking = 0; |
249 | self.running = 0; | 290 | self.running = 0; |
250 | NSDate *startDate = [date beginningAtMidnightOfDay]; | 291 | NSDate *startDate = [date beginningAtMidnightOfDay]; |
251 | NSDate *endDate = [startDate dateByAddingTimeInterval:(24*60*60 - 1)]; | 292 | NSDate *endDate = [startDate dateByAddingTimeInterval:(24*60*60 - 1)]; |
252 | 293 | ||
253 | HomeViewController __weak *weakSelf = self; | 294 | HomeViewController __weak *weakSelf = self; |
254 | dispatch_queue_t myQueue = dispatch_queue_create("mobileworld.jp.lifelog.forDay", NULL); | 295 | dispatch_queue_t myQueue = dispatch_queue_create("mobileworld.jp.lifelog.forDay", NULL); |
255 | dispatch_async(myQueue, ^{ | 296 | dispatch_async(myQueue, ^{ |
256 | if (weakSelf == nil) { | 297 | if (weakSelf == nil) { |
257 | return ; | 298 | return ; |
258 | } | 299 | } |
259 | 300 | ||
260 | [weakSelf.motionActivityManager queryActivityStartingFromDate:startDate toDate:endDate toQueue:_operationQueue withHandler:^(NSArray<CMMotionActivity *> * _Nullable activities, NSError * _Nullable error) { | 301 | [weakSelf.motionActivityManager queryActivityStartingFromDate:startDate toDate:endDate toQueue:_operationQueue withHandler:^(NSArray<CMMotionActivity *> * _Nullable activities, NSError * _Nullable error) { |
261 | if (error || activities.count <= 0) { | 302 | if (error || activities.count <= 0) { |
262 | dispatch_async(dispatch_get_main_queue(), ^{ | 303 | dispatch_async(dispatch_get_main_queue(), ^{ |
263 | [weakSelf updateStepUI]; | 304 | [weakSelf updateStepUI]; |
264 | }); | 305 | }); |
265 | return ; | 306 | return ; |
266 | } | 307 | } |
267 | // set EndDate | 308 | // set EndDate |
268 | NSMutableArray *arrayActivities = [[NSMutableArray alloc] init]; | 309 | NSMutableArray *arrayActivities = [[NSMutableArray alloc] init]; |
269 | for (int i = 0; i < activities.count; i++) { | 310 | for (int i = 0; i < activities.count; i++) { |
270 | CMMotionActivity *activity = [activities objectAtIndex:i]; | 311 | CMMotionActivity *activity = [activities objectAtIndex:i]; |
271 | CMMotionActivityExtra *activityExtra = [[CMMotionActivityExtra alloc] init]; | 312 | CMMotionActivityExtra *activityExtra = [[CMMotionActivityExtra alloc] init]; |
272 | activityExtra.activity = activity; | 313 | activityExtra.activity = activity; |
273 | if (i == activities.count - 1) { | 314 | if (i == activities.count - 1) { |
274 | activityExtra.endDate = endDate; | 315 | activityExtra.endDate = endDate; |
275 | } | 316 | } |
276 | else { | 317 | else { |
277 | CMMotionActivity *activityNext = [activities objectAtIndex:i+1]; | 318 | CMMotionActivity *activityNext = [activities objectAtIndex:i+1]; |
278 | // activityExtra.endDate = [activityNext.startDate dateByAddingTimeInterval:-1]; | 319 | // activityExtra.endDate = [activityNext.startDate dateByAddingTimeInterval:-1]; |
279 | activityExtra.endDate = activityNext.startDate; | 320 | activityExtra.endDate = activityNext.startDate; |
280 | } | 321 | } |
281 | [arrayActivities addObject:activityExtra]; | 322 | [arrayActivities addObject:activityExtra]; |
282 | } | 323 | } |
283 | // PhongNV | 324 | // PhongNV |
284 | weakSelf.currentIndex = 0; | 325 | weakSelf.currentIndex = 0; |
285 | [weakSelf save20objectOfActivityExtras:arrayActivities]; | 326 | [weakSelf save20objectOfActivityExtras:arrayActivities]; |
286 | }]; | 327 | }]; |
287 | }); | 328 | }); |
288 | } | 329 | } |
289 | } | 330 | } |
290 | 331 | ||
291 | - (void)complete20Request:(NSArray *)activities { | 332 | - (void)complete20Request:(NSArray *)activities { |
292 | if (self.totalRequest == self.countComplete) { | 333 | if (self.totalRequest == self.countComplete) { |
293 | self.totalRequest = 0; | 334 | self.totalRequest = 0; |
294 | self.countComplete = 0; | 335 | self.countComplete = 0; |
295 | self.currentIndex++; | 336 | self.currentIndex++; |
296 | [self save20objectOfActivityExtras:activities]; | 337 | [self save20objectOfActivityExtras:activities]; |
297 | } | 338 | } |
298 | } | 339 | } |
299 | - (void)save20objectOfActivityExtras:(NSArray *)activities | 340 | - (void)save20objectOfActivityExtras:(NSArray *)activities |
300 | { | 341 | { |
301 | int result = floor(activities.count / maxRequest); | 342 | int result = floor(activities.count / maxRequest); |
302 | if (activities.count <= 0 || self.currentIndex > result) { | 343 | if (activities.count <= 0 || self.currentIndex > result) { |
303 | self.totalRequest = 0; | 344 | self.totalRequest = 0; |
304 | self.countComplete = 0; | 345 | self.countComplete = 0; |
305 | self.currentIndex = 0; | 346 | self.currentIndex = 0; |
306 | dispatch_async(dispatch_get_main_queue(), ^{ | 347 | dispatch_async(dispatch_get_main_queue(), ^{ |
307 | [self updateStepUI]; | 348 | [self updateStepUI]; |
308 | }); | 349 | }); |
309 | return; | 350 | return; |
310 | } | 351 | } |
311 | 352 | ||
312 | HomeViewController __weak *weakSelf = self; | 353 | HomeViewController __weak *weakSelf = self; |
313 | for (NSInteger index = self.currentIndex*maxRequest; index < self.currentIndex*maxRequest + maxRequest; index++) { | 354 | for (NSInteger index = self.currentIndex*maxRequest; index < self.currentIndex*maxRequest + maxRequest; index++) { |
314 | if ((self.currentIndex*maxRequest + maxRequest) >= activities.count) { | 355 | if ((self.currentIndex*maxRequest + maxRequest) >= activities.count) { |
315 | self.totalRequest = (int)(activities.count - self.currentIndex*maxRequest); | 356 | self.totalRequest = (int)(activities.count - self.currentIndex*maxRequest); |
316 | if (self.totalRequest <= 0) { | 357 | if (self.totalRequest <= 0) { |
317 | [weakSelf complete20Request:activities]; | 358 | [weakSelf complete20Request:activities]; |
318 | } | 359 | } |
319 | } | 360 | } |
320 | else { | 361 | else { |
321 | self.totalRequest = (int)maxRequest; | 362 | self.totalRequest = (int)maxRequest; |
322 | } | 363 | } |
323 | if (index < activities.count) { | 364 | if (index < activities.count) { |
324 | CMMotionActivityExtra *activityExtra = [activities objectAtIndex:index]; | 365 | CMMotionActivityExtra *activityExtra = [activities objectAtIndex:index]; |
325 | [self.pedometer queryPedometerDataFromDate:activityExtra.activity.startDate toDate:activityExtra.endDate withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) { | 366 | [self.pedometer queryPedometerDataFromDate:activityExtra.activity.startDate toDate:activityExtra.endDate withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) { |
326 | if (weakSelf == nil) { | 367 | if (weakSelf == nil) { |
327 | return ; | 368 | return ; |
328 | } | 369 | } |
329 | NSInteger numberStep = [pedometerData.numberOfSteps integerValue]; | 370 | NSInteger numberStep = [pedometerData.numberOfSteps integerValue]; |
330 | int mode = 1; | 371 | int mode = 1; |
331 | if (activityExtra.activity.cycling) { | 372 | if (activityExtra.activity.cycling) { |
332 | mode = 3; | 373 | mode = 3; |
333 | } | 374 | } |
334 | else if (activityExtra.activity.walking) { | 375 | else if (activityExtra.activity.walking) { |
335 | mode = 1; | 376 | mode = 1; |
336 | } | 377 | } |
337 | else if (activityExtra.activity.running) { | 378 | else if (activityExtra.activity.running) { |
338 | mode = 2; | 379 | mode = 2; |
339 | } | 380 | } |
340 | else { | 381 | else { |
341 | // unknown | 382 | // unknown |
342 | } | 383 | } |
343 | // save step to server | 384 | // save step to server |
344 | if (numberStep > 0) { | 385 | if (numberStep > 0) { |
345 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | 386 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
346 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | 387 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; |
347 | NSString *dateBegin = [dateFormatter stringFromDate:activityExtra.activity.startDate]; | 388 | NSString *dateBegin = [dateFormatter stringFromDate:activityExtra.activity.startDate]; |
348 | NSString *dateEnd = [dateFormatter stringFromDate:activityExtra.endDate]; | 389 | NSString *dateEnd = [dateFormatter stringFromDate:activityExtra.endDate]; |
349 | NSLog(@"dateBegin: %@ | dateEnd: %@ | numberStep: %li", dateBegin, dateEnd, numberStep); | 390 | // NSLog(@"dateBegin: %@ | dateEnd: %@ | numberStep: %li", dateBegin, dateEnd, numberStep); |
350 | [[ServerAPI server] requestCreateLog:mode withStep:(int)numberStep startDate:dateBegin endDate:dateEnd CompletionHandler:^(NSError *error) { | 391 | [[ServerAPI server] requestCreateLog:mode withStep:(int)numberStep startDate:dateBegin endDate:dateEnd CompletionHandler:^(NSError *error) { |
351 | if (error) { | 392 | if (error) { |
352 | NSLog(@"Error: %@", error); | 393 | NSLog(@"Error: %@", error); |
353 | } | 394 | } |
354 | weakSelf.countComplete++; | 395 | weakSelf.countComplete++; |
355 | [weakSelf complete20Request:activities]; | 396 | [weakSelf complete20Request:activities]; |
356 | }]; | 397 | }]; |
357 | } | 398 | } |
358 | else { | 399 | else { |
359 | weakSelf.countComplete++; | 400 | weakSelf.countComplete++; |
360 | [weakSelf complete20Request:activities]; | 401 | [weakSelf complete20Request:activities]; |
361 | } | 402 | } |
362 | }]; | 403 | }]; |
363 | } | 404 | } |
364 | } | 405 | } |
365 | } | 406 | } |
366 | 407 | ||
367 | - (void)updateStepUI | 408 | - (void)updateStepUI |
368 | { | 409 | { |
369 | [self requestTopByDate:self.dateCurrent]; | 410 | [self requestTopByDate:self.dateCurrent]; |
370 | } | 411 | } |
371 | 412 | ||
372 | - (void)saveDataStep7LastDay | 413 | - (void)saveDataStep7LastDay |
373 | { | 414 | { |
374 | NSDate *dateNow = [NSDate date]; | 415 | NSDate *dateNow = [NSDate date]; |
375 | for (int index = 0; index < 7; index++) { | 416 | for (int index = 0; index < 7; index++) { |
376 | dateNow = [dateNow dateByAddingTimeInterval:-(24*60*60)]; | 417 | dateNow = [dateNow dateByAddingTimeInterval:-(24*60*60)]; |
377 | [self saveStepByDate:dateNow]; | 418 | [self saveStepByDate:dateNow]; |
378 | } | 419 | } |
379 | } | 420 | } |
380 | 421 | ||
381 | - (void)saveStepByDate:(NSDate *)date | 422 | - (void)saveStepByDate:(NSDate *)date |
382 | { | 423 | { |
383 | if ([CMMotionActivityManager isActivityAvailable]) { | 424 | if ([CMMotionActivityManager isActivityAvailable]) { |
384 | NSDate *startDate = [date beginningAtMidnightOfDay]; | 425 | NSDate *startDate = [date beginningAtMidnightOfDay]; |
385 | NSDate *endDate = [startDate dateByAddingTimeInterval:(24*60*60 - 1)]; | 426 | NSDate *endDate = [startDate dateByAddingTimeInterval:(24*60*60 - 1)]; |
386 | 427 | ||
387 | HomeViewController __weak *weakSelf = self; | 428 | HomeViewController __weak *weakSelf = self; |
388 | dispatch_queue_t myQueue = dispatch_queue_create("mobileworld.jp.lifelog.7lastday", NULL); | 429 | dispatch_queue_t myQueue = dispatch_queue_create("mobileworld.jp.lifelog.7lastday", NULL); |
389 | dispatch_async(myQueue, ^{ | 430 | dispatch_async(myQueue, ^{ |
390 | if (weakSelf == nil) { | 431 | if (weakSelf == nil) { |
391 | return ; | 432 | return ; |
392 | } | 433 | } |
393 | 434 | ||
394 | [weakSelf.motionActivityManager queryActivityStartingFromDate:startDate toDate:endDate toQueue:_operationQueue withHandler:^(NSArray<CMMotionActivity *> * _Nullable activities, NSError * _Nullable error) { | 435 | [weakSelf.motionActivityManager queryActivityStartingFromDate:startDate toDate:endDate toQueue:_operationQueue withHandler:^(NSArray<CMMotionActivity *> * _Nullable activities, NSError * _Nullable error) { |
395 | if (error || activities.count <= 0) { | 436 | if (error || activities.count <= 0) { |
396 | return ; | 437 | return ; |
397 | } | 438 | } |
398 | // set EndDate | 439 | // set EndDate |
399 | NSMutableArray *arrayActivities = [[NSMutableArray alloc] init]; | 440 | NSMutableArray *arrayActivities = [[NSMutableArray alloc] init]; |
400 | for (int i = 0; i < activities.count; i++) { | 441 | for (int i = 0; i < activities.count; i++) { |
401 | CMMotionActivity *activity = [activities objectAtIndex:i]; | 442 | CMMotionActivity *activity = [activities objectAtIndex:i]; |
402 | CMMotionActivityExtra *activityExtra = [[CMMotionActivityExtra alloc] init]; | 443 | CMMotionActivityExtra *activityExtra = [[CMMotionActivityExtra alloc] init]; |
403 | activityExtra.activity = activity; | 444 | activityExtra.activity = activity; |
404 | if (i == activities.count - 1) { | 445 | if (i == activities.count - 1) { |
405 | activityExtra.endDate = endDate; | 446 | activityExtra.endDate = endDate; |
406 | } | 447 | } |
407 | else { | 448 | else { |
408 | CMMotionActivity *activityNext = [activities objectAtIndex:i+1]; | 449 | CMMotionActivity *activityNext = [activities objectAtIndex:i+1]; |
409 | activityExtra.endDate = [activityNext.startDate dateByAddingTimeInterval:-1]; | 450 | activityExtra.endDate = [activityNext.startDate dateByAddingTimeInterval:-1]; |
410 | } | 451 | } |
411 | [arrayActivities addObject:activityExtra]; | 452 | [arrayActivities addObject:activityExtra]; |
412 | } | 453 | } |
413 | 454 | ||
414 | for (CMMotionActivityExtra *activityExtra in arrayActivities) { | 455 | for (CMMotionActivityExtra *activityExtra in arrayActivities) { |
415 | [weakSelf.pedometer queryPedometerDataFromDate:activityExtra.activity.startDate toDate:activityExtra.endDate withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) { | 456 | [weakSelf.pedometer queryPedometerDataFromDate:activityExtra.activity.startDate toDate:activityExtra.endDate withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) { |
416 | NSInteger numberStep = [pedometerData.numberOfSteps integerValue]; | 457 | NSInteger numberStep = [pedometerData.numberOfSteps integerValue]; |
417 | int mode = 1; | 458 | int mode = 1; |
418 | if (activityExtra.activity.cycling) { | 459 | if (activityExtra.activity.cycling) { |
419 | mode = 3; | 460 | mode = 3; |
420 | } | 461 | } |
421 | else if (activityExtra.activity.walking) { | 462 | else if (activityExtra.activity.walking) { |
422 | mode = 1; | 463 | mode = 1; |
423 | } | 464 | } |
424 | else if (activityExtra.activity.running) { | 465 | else if (activityExtra.activity.running) { |
425 | mode = 2; | 466 | mode = 2; |
426 | } | 467 | } |
427 | else { | 468 | else { |
428 | // unknown | 469 | // unknown |
429 | } | 470 | } |
430 | 471 | ||
431 | // save step to server | 472 | // save step to server |
432 | if (numberStep > 0) { | 473 | if (numberStep > 0) { |
433 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | 474 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
434 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | 475 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; |
435 | NSString *dateBegin = [dateFormatter stringFromDate:activityExtra.activity.startDate]; | 476 | NSString *dateBegin = [dateFormatter stringFromDate:activityExtra.activity.startDate]; |
436 | NSString *dateEnd = [dateFormatter stringFromDate:activityExtra.endDate]; | 477 | NSString *dateEnd = [dateFormatter stringFromDate:activityExtra.endDate]; |
437 | [[ServerAPI server] requestCreateLog:mode withStep:(int)numberStep startDate:dateBegin endDate:dateEnd CompletionHandler:^(NSError *error) { | 478 | [[ServerAPI server] requestCreateLog:mode withStep:(int)numberStep startDate:dateBegin endDate:dateEnd CompletionHandler:^(NSError *error) { |
438 | if (error) { | 479 | if (error) { |
439 | NSLog(@"Error: %@", error); | 480 | NSLog(@"Error: %@", error); |
440 | } | 481 | } |
441 | }]; | 482 | }]; |
442 | } | 483 | } |
443 | }]; | 484 | }]; |
444 | } | 485 | } |
445 | }]; | 486 | }]; |
446 | }); | 487 | }); |
447 | } | 488 | } |
448 | } | 489 | } |
449 | 490 | ||
450 | - (void)updateStepUI:(TargetInfor *)targetInfor | 491 | - (void)updateStepUI:(TargetInfor *)targetInfor |
451 | { | 492 | { |
452 | NSString *stringTargetStep = [targetInfor.target_step stringByReplacingOccurrencesOfString:@"," withString:@""]; | 493 | NSString *stringTargetStep = [targetInfor.target_step stringByReplacingOccurrencesOfString:@"," withString:@""]; |
453 | targetStep = [stringTargetStep integerValue]; | 494 | targetStep = [stringTargetStep integerValue]; |
454 | self.lblValueStep.text = targetInfor.num_step; | 495 | self.lblValueStep.text = targetInfor.num_step; |
455 | self.lblValueStepOther.text = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"lifelog.today.remaining.other", nil), targetInfor.remaining_step]; | 496 | self.lblValueStepOther.text = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"lifelog.today.remaining.other", nil), targetInfor.remaining_step]; |
456 | self.lblPercent.text = [NSString stringWithFormat:@"%@ %i%@", NSLocalizedString(@"lifelog.today.text.percent", nil), [targetInfor.complete_percent intValue], NSLocalizedString(@"lifelog.today.percent", nil)]; | 497 | self.lblPercent.text = [NSString stringWithFormat:@"%@ %i%@", NSLocalizedString(@"lifelog.today.text.percent", nil), [targetInfor.complete_percent intValue], NSLocalizedString(@"lifelog.today.percent", nil)]; |
457 | } | 498 | } |
458 | 499 | ||
459 | - (void)updateNoticeUI:(HomeObject *)homeObject | 500 | - (void)updateNoticeUI:(HomeObject *)homeObject |
460 | { | 501 | { |
461 | NSString *stringNotice = @""; | 502 | NSString *stringNotice = @""; |
462 | for (NoticeInfor *notice in homeObject.listNotice) { | 503 | for (NoticeInfor *notice in homeObject.listNotice) { |
463 | NSString *noticeString = [NSString stringWithFormat:@"%@\n", notice.notice_content]; | 504 | NSString *noticeString = [NSString stringWithFormat:@"%@\n", notice.notice_content]; |
464 | stringNotice = [stringNotice stringByAppendingString:noticeString]; | 505 | stringNotice = [stringNotice stringByAppendingString:noticeString]; |
465 | } | 506 | } |
466 | _tvNotice.text = stringNotice; | 507 | _tvNotice.text = stringNotice; |
467 | } | 508 | } |
468 | 509 | ||
469 | - (void)resetStepUI | 510 | - (void)resetStepUI |
470 | { | 511 | { |
471 | self.lblValueStep.text = @""; | 512 | self.lblValueStep.text = @""; |
472 | self.lblValueStepOther.text = @""; | 513 | self.lblValueStepOther.text = @""; |
473 | self.lblPercent.text = @""; | 514 | self.lblPercent.text = @""; |
474 | } | 515 | } |
475 | 516 | ||
476 | @end | 517 | @end |
477 | 518 |
LifeLog/LifeLog/HomeViewController.xib
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | 2 | <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> |
3 | <device id="retina4_7" orientation="portrait"> | 3 | <device id="retina4_7" orientation="portrait"> |
4 | <adaptation id="fullscreen"/> | 4 | <adaptation id="fullscreen"/> |
5 | </device> | 5 | </device> |
6 | <dependencies> | 6 | <dependencies> |
7 | <deployment identifier="iOS"/> | 7 | <deployment identifier="iOS"/> |
8 | <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/> | 8 | <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/> |
9 | <capability name="Aspect ratio constraints" minToolsVersion="5.1"/> | 9 | <capability name="Aspect ratio constraints" minToolsVersion="5.1"/> |
10 | <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | 10 | <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> |
11 | </dependencies> | 11 | </dependencies> |
12 | <objects> | 12 | <objects> |
13 | <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HomeViewController"> | 13 | <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HomeViewController"> |
14 | <connections> | 14 | <connections> |
15 | <outlet property="avatar" destination="J2A-tf-wH0" id="FdR-Zg-4ye"/> | 15 | <outlet property="avatar" destination="J2A-tf-wH0" id="FdR-Zg-4ye"/> |
16 | <outlet property="lblDateCurrent" destination="IaR-IO-4RA" id="nVS-KW-X4d"/> | 16 | <outlet property="lblDateCurrent" destination="IaR-IO-4RA" id="nVS-KW-X4d"/> |
17 | <outlet property="lblNotice" destination="lnt-4H-Ao8" id="aoM-JS-VHg"/> | 17 | <outlet property="lblNotice" destination="lnt-4H-Ao8" id="aoM-JS-VHg"/> |
18 | <outlet property="lblPercent" destination="DuE-Dh-nEe" id="Yz4-VO-P2h"/> | 18 | <outlet property="lblPercent" destination="DuE-Dh-nEe" id="Yz4-VO-P2h"/> |
19 | <outlet property="lblTitle" destination="u3S-9u-GMZ" id="7C6-gv-vPu"/> | 19 | <outlet property="lblTitle" destination="u3S-9u-GMZ" id="7C6-gv-vPu"/> |
20 | <outlet property="lblUnitStep" destination="wfu-aB-xXm" id="4Ms-pS-D2m"/> | 20 | <outlet property="lblUnitStep" destination="wfu-aB-xXm" id="4Ms-pS-D2m"/> |
21 | <outlet property="lblValueStep" destination="TUf-Tp-93t" id="qAh-fl-oW4"/> | 21 | <outlet property="lblValueStep" destination="TUf-Tp-93t" id="qAh-fl-oW4"/> |
22 | <outlet property="lblValueStepOther" destination="3Xj-IB-96h" id="yXj-HA-fDR"/> | 22 | <outlet property="lblValueStepOther" destination="3Xj-IB-96h" id="yXj-HA-fDR"/> |
23 | <outlet property="segmentHome" destination="ibb-Yl-iqu" id="lE6-pr-GgT"/> | 23 | <outlet property="segmentHome" destination="ibb-Yl-iqu" id="lE6-pr-GgT"/> |
24 | <outlet property="tvNotice" destination="kdD-rj-BtX" id="t6k-l8-l2N"/> | 24 | <outlet property="tvNotice" destination="kdD-rj-BtX" id="t6k-l8-l2N"/> |
25 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> | 25 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> |
26 | </connections> | 26 | </connections> |
27 | </placeholder> | 27 | </placeholder> |
28 | <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | 28 | <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> |
29 | <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> | 29 | <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> |
30 | <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | 30 | <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> |
31 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | 31 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
32 | <subviews> | 32 | <subviews> |
33 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="HOME" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="u3S-9u-GMZ" userLabel="LabelTitle"> | 33 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="HOME" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="u3S-9u-GMZ" userLabel="LabelTitle"> |
34 | <rect key="frame" x="0.0" y="0.0" width="375" height="44"/> | 34 | <rect key="frame" x="0.0" y="0.0" width="375" height="44"/> |
35 | <color key="backgroundColor" red="0.098039215686274508" green="0.098039215686274508" blue="0.098039215686274508" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | 35 | <color key="backgroundColor" red="0.098039215686274508" green="0.098039215686274508" blue="0.098039215686274508" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> |
36 | <constraints> | 36 | <constraints> |
37 | <constraint firstAttribute="height" constant="44" id="8z2-GM-1iE"/> | 37 | <constraint firstAttribute="height" constant="44" id="8z2-GM-1iE"/> |
38 | </constraints> | 38 | </constraints> |
39 | <fontDescription key="fontDescription" type="system" pointSize="23"/> | 39 | <fontDescription key="fontDescription" type="system" pointSize="23"/> |
40 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 40 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
41 | <nil key="highlightedColor"/> | 41 | <nil key="highlightedColor"/> |
42 | </label> | 42 | </label> |
43 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="LPY-Zl-cOp" userLabel="ButtonMenu"> | 43 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="LPY-Zl-cOp" userLabel="ButtonMenu"> |
44 | <rect key="frame" x="335" y="7" width="30" height="30"/> | 44 | <rect key="frame" x="335" y="7" width="30" height="30"/> |
45 | <constraints> | 45 | <constraints> |
46 | <constraint firstAttribute="width" constant="30" id="5Ve-P6-6G7"/> | 46 | <constraint firstAttribute="width" constant="30" id="5Ve-P6-6G7"/> |
47 | <constraint firstAttribute="width" secondItem="LPY-Zl-cOp" secondAttribute="height" multiplier="1:1" id="6V0-0o-71r"/> | 47 | <constraint firstAttribute="width" secondItem="LPY-Zl-cOp" secondAttribute="height" multiplier="1:1" id="6V0-0o-71r"/> |
48 | </constraints> | 48 | </constraints> |
49 | <state key="normal" image="icon_menu"/> | 49 | <state key="normal" image="icon_menu"/> |
50 | <connections> | 50 | <connections> |
51 | <action selector="menuButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="HrU-er-jwh"/> | 51 | <action selector="menuButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="HrU-er-jwh"/> |
52 | </connections> | 52 | </connections> |
53 | </button> | 53 | </button> |
54 | <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="avatar_default" translatesAutoresizingMaskIntoConstraints="NO" id="J2A-tf-wH0" userLabel="avatar"> | 54 | <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="avatar_default" translatesAutoresizingMaskIntoConstraints="NO" id="J2A-tf-wH0" userLabel="avatar"> |
55 | <rect key="frame" x="8" y="54" width="80" height="80"/> | 55 | <rect key="frame" x="8" y="54" width="80" height="80"/> |
56 | <constraints> | 56 | <constraints> |
57 | <constraint firstAttribute="width" secondItem="J2A-tf-wH0" secondAttribute="height" multiplier="1:1" id="TVn-eB-Jhs"/> | 57 | <constraint firstAttribute="width" secondItem="J2A-tf-wH0" secondAttribute="height" multiplier="1:1" id="TVn-eB-Jhs"/> |
58 | <constraint firstAttribute="width" constant="80" id="YGa-LO-1Mu"/> | 58 | <constraint firstAttribute="width" constant="80" id="YGa-LO-1Mu"/> |
59 | </constraints> | 59 | </constraints> |
60 | </imageView> | 60 | </imageView> |
61 | <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_left" translatesAutoresizingMaskIntoConstraints="NO" id="vRa-cr-YTe" userLabel="icon_left"> | 61 | <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_left" translatesAutoresizingMaskIntoConstraints="NO" id="vRa-cr-YTe" userLabel="icon_left"> |
62 | <rect key="frame" x="98" y="79" width="30" height="30"/> | 62 | <rect key="frame" x="98" y="79" width="30" height="30"/> |
63 | <constraints> | 63 | <constraints> |
64 | <constraint firstAttribute="width" constant="30" id="UZi-wZ-The"/> | 64 | <constraint firstAttribute="width" constant="30" id="UZi-wZ-The"/> |
65 | <constraint firstAttribute="width" secondItem="vRa-cr-YTe" secondAttribute="height" multiplier="1:1" id="itE-d2-PsT"/> | 65 | <constraint firstAttribute="width" secondItem="vRa-cr-YTe" secondAttribute="height" multiplier="1:1" id="itE-d2-PsT"/> |
66 | </constraints> | 66 | </constraints> |
67 | </imageView> | 67 | </imageView> |
68 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="b6V-Bi-4oz" userLabel="ButtonLeft"> | 68 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="b6V-Bi-4oz" userLabel="ButtonLeft"> |
69 | <rect key="frame" x="88" y="69" width="50" height="50"/> | 69 | <rect key="frame" x="88" y="69" width="50" height="50"/> |
70 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 70 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
71 | <constraints> | 71 | <constraints> |
72 | <constraint firstAttribute="width" secondItem="b6V-Bi-4oz" secondAttribute="height" multiplier="1:1" id="GYG-2B-e1R"/> | 72 | <constraint firstAttribute="width" secondItem="b6V-Bi-4oz" secondAttribute="height" multiplier="1:1" id="GYG-2B-e1R"/> |
73 | <constraint firstAttribute="width" constant="50" id="bgQ-rD-KZD"/> | 73 | <constraint firstAttribute="width" constant="50" id="bgQ-rD-KZD"/> |
74 | </constraints> | 74 | </constraints> |
75 | <connections> | 75 | <connections> |
76 | <action selector="leftButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="Bzk-y5-Lre"/> | 76 | <action selector="leftButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="Bzk-y5-Lre"/> |
77 | </connections> | 77 | </connections> |
78 | </button> | 78 | </button> |
79 | <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_right" translatesAutoresizingMaskIntoConstraints="NO" id="Low-8n-pqa" userLabel="icon_right"> | 79 | <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_right" translatesAutoresizingMaskIntoConstraints="NO" id="Low-8n-pqa" userLabel="icon_right"> |
80 | <rect key="frame" x="335" y="79" width="30" height="30"/> | 80 | <rect key="frame" x="335" y="79" width="30" height="30"/> |
81 | <constraints> | 81 | <constraints> |
82 | <constraint firstAttribute="width" constant="30" id="jTd-Xb-RdV"/> | 82 | <constraint firstAttribute="width" constant="30" id="jTd-Xb-RdV"/> |
83 | <constraint firstAttribute="width" secondItem="Low-8n-pqa" secondAttribute="height" multiplier="1:1" id="pft-kU-wDw"/> | 83 | <constraint firstAttribute="width" secondItem="Low-8n-pqa" secondAttribute="height" multiplier="1:1" id="pft-kU-wDw"/> |
84 | </constraints> | 84 | </constraints> |
85 | </imageView> | 85 | </imageView> |
86 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="at8-co-gC4" userLabel="ButtonRight"> | 86 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="at8-co-gC4" userLabel="ButtonRight"> |
87 | <rect key="frame" x="325" y="69" width="50" height="50"/> | 87 | <rect key="frame" x="325" y="69" width="50" height="50"/> |
88 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 88 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
89 | <constraints> | 89 | <constraints> |
90 | <constraint firstAttribute="width" constant="50" id="dpm-ie-7c4"/> | 90 | <constraint firstAttribute="width" constant="50" id="dpm-ie-7c4"/> |
91 | <constraint firstAttribute="width" secondItem="at8-co-gC4" secondAttribute="height" multiplier="1:1" id="wDO-Tw-aYK"/> | 91 | <constraint firstAttribute="width" secondItem="at8-co-gC4" secondAttribute="height" multiplier="1:1" id="wDO-Tw-aYK"/> |
92 | </constraints> | 92 | </constraints> |
93 | <connections> | 93 | <connections> |
94 | <action selector="rightButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="0jR-UP-2ia"/> | 94 | <action selector="rightButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="0jR-UP-2ia"/> |
95 | </connections> | 95 | </connections> |
96 | </button> | 96 | </button> |
97 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2017年1月1日" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IaR-IO-4RA"> | 97 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2017年1月1日" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IaR-IO-4RA"> |
98 | <rect key="frame" x="136" y="79" width="191" height="30"/> | 98 | <rect key="frame" x="136" y="79" width="191" height="30"/> |
99 | <constraints> | 99 | <constraints> |
100 | <constraint firstAttribute="height" constant="30" id="MsO-aD-MZ3"/> | 100 | <constraint firstAttribute="height" constant="30" id="MsO-aD-MZ3"/> |
101 | </constraints> | 101 | </constraints> |
102 | <fontDescription key="fontDescription" type="system" pointSize="22"/> | 102 | <fontDescription key="fontDescription" type="system" pointSize="22"/> |
103 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 103 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
104 | <nil key="highlightedColor"/> | 104 | <nil key="highlightedColor"/> |
105 | </label> | 105 | </label> |
106 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TUf-Tp-93t" userLabel="valueStep"> | 106 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TUf-Tp-93t" userLabel="valueStep"> |
107 | <rect key="frame" x="20" y="139" width="275" height="40"/> | 107 | <rect key="frame" x="20" y="139" width="275" height="40"/> |
108 | <constraints> | 108 | <constraints> |
109 | <constraint firstAttribute="height" constant="40" id="6Wd-CK-kPs"/> | 109 | <constraint firstAttribute="height" constant="40" id="6Wd-CK-kPs"/> |
110 | </constraints> | 110 | </constraints> |
111 | <fontDescription key="fontDescription" type="system" pointSize="45"/> | 111 | <fontDescription key="fontDescription" type="system" pointSize="45"/> |
112 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 112 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
113 | <nil key="highlightedColor"/> | 113 | <nil key="highlightedColor"/> |
114 | </label> | 114 | </label> |
115 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wfu-aB-xXm" userLabel="unitStep"> | 115 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="step" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wfu-aB-xXm" userLabel="unitStep"> |
116 | <rect key="frame" x="305" y="149" width="50" height="30"/> | 116 | <rect key="frame" x="305" y="149" width="50" height="30"/> |
117 | <constraints> | 117 | <constraints> |
118 | <constraint firstAttribute="width" constant="50" id="oQw-JM-dmo"/> | 118 | <constraint firstAttribute="width" constant="50" id="oQw-JM-dmo"/> |
119 | <constraint firstAttribute="height" constant="30" id="pV2-7i-dZB"/> | 119 | <constraint firstAttribute="height" constant="30" id="pV2-7i-dZB"/> |
120 | </constraints> | 120 | </constraints> |
121 | <fontDescription key="fontDescription" type="system" pointSize="25"/> | 121 | <fontDescription key="fontDescription" type="system" pointSize="25"/> |
122 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 122 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
123 | <nil key="highlightedColor"/> | 123 | <nil key="highlightedColor"/> |
124 | </label> | 124 | </label> |
125 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VAz-hq-dvR"> | 125 | <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VAz-hq-dvR"> |
126 | <rect key="frame" x="157" y="525" width="60" height="30"/> | 126 | <rect key="frame" x="157" y="525" width="60" height="30"/> |
127 | <constraints> | 127 | <constraints> |
128 | <constraint firstAttribute="width" constant="60" id="KzL-jP-qZn"/> | 128 | <constraint firstAttribute="width" constant="60" id="KzL-jP-qZn"/> |
129 | <constraint firstAttribute="height" constant="30" id="kdw-th-wDS"/> | 129 | <constraint firstAttribute="height" constant="30" id="kdw-th-wDS"/> |
130 | </constraints> | 130 | </constraints> |
131 | <state key="normal" title="TODAY"> | 131 | <state key="normal" title="TODAY"> |
132 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 132 | <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
133 | </state> | 133 | </state> |
134 | <connections> | 134 | <connections> |
135 | <action selector="todayButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="KoT-el-kxw"/> | 135 | <action selector="todayButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="KoT-el-kxw"/> |
136 | </connections> | 136 | </connections> |
137 | </button> | 137 | </button> |
138 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3Xj-IB-96h"> | 138 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3Xj-IB-96h"> |
139 | <rect key="frame" x="8" y="187" width="359" height="30"/> | 139 | <rect key="frame" x="8" y="187" width="359" height="30"/> |
140 | <constraints> | 140 | <constraints> |
141 | <constraint firstAttribute="height" constant="30" id="B7Z-yO-b6M"/> | 141 | <constraint firstAttribute="height" constant="30" id="B7Z-yO-b6M"/> |
142 | </constraints> | 142 | </constraints> |
143 | <fontDescription key="fontDescription" type="system" pointSize="20"/> | 143 | <fontDescription key="fontDescription" type="system" pointSize="20"/> |
144 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 144 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
145 | <nil key="highlightedColor"/> | 145 | <nil key="highlightedColor"/> |
146 | </label> | 146 | </label> |
147 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DuE-Dh-nEe"> | 147 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DuE-Dh-nEe"> |
148 | <rect key="frame" x="8" y="225" width="359" height="30"/> | 148 | <rect key="frame" x="8" y="225" width="359" height="30"/> |
149 | <constraints> | 149 | <constraints> |
150 | <constraint firstAttribute="height" constant="30" id="6YJ-rf-mz3"/> | 150 | <constraint firstAttribute="height" constant="30" id="6YJ-rf-mz3"/> |
151 | </constraints> | 151 | </constraints> |
152 | <fontDescription key="fontDescription" type="system" pointSize="20"/> | 152 | <fontDescription key="fontDescription" type="system" pointSize="20"/> |
153 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 153 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
154 | <nil key="highlightedColor"/> | 154 | <nil key="highlightedColor"/> |
155 | </label> | 155 | </label> |
156 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="お知らせ" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lnt-4H-Ao8"> | 156 | <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="お知らせ" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lnt-4H-Ao8"> |
157 | <rect key="frame" x="8" y="275" width="359" height="30"/> | 157 | <rect key="frame" x="8" y="275" width="359" height="30"/> |
158 | <constraints> | 158 | <constraints> |
159 | <constraint firstAttribute="height" constant="30" id="isj-iQ-BcF"/> | 159 | <constraint firstAttribute="height" constant="30" id="isj-iQ-BcF"/> |
160 | </constraints> | 160 | </constraints> |
161 | <fontDescription key="fontDescription" type="system" pointSize="20"/> | 161 | <fontDescription key="fontDescription" type="system" pointSize="25"/> |
162 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 162 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
163 | <nil key="highlightedColor"/> | 163 | <nil key="highlightedColor"/> |
164 | </label> | 164 | </label> |
165 | <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_other" translatesAutoresizingMaskIntoConstraints="NO" id="BoP-c1-c0q"> | ||
166 | <rect key="frame" x="20" y="313" width="75" height="67"/> | ||
167 | <constraints> | ||
168 | <constraint firstAttribute="width" constant="75" id="lKw-2n-DMo"/> | ||
169 | <constraint firstAttribute="height" constant="67" id="m58-CT-3kB"/> | ||
170 | </constraints> | ||
171 | </imageView> | ||
172 | <segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="ibb-Yl-iqu"> | 165 | <segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="ibb-Yl-iqu"> |
173 | <rect key="frame" x="75" y="575" width="224" height="29"/> | 166 | <rect key="frame" x="75" y="575" width="224" height="29"/> |
174 | <segments> | 167 | <segments> |
175 | <segment title="BIKE"/> | 168 | <segment title="BIKE"/> |
176 | <segment title="WALKING"/> | 169 | <segment title="WALKING"/> |
177 | <segment title="RUNNING"/> | 170 | <segment title="RUNNING"/> |
178 | </segments> | 171 | </segments> |
179 | <color key="tintColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/> | 172 | <color key="tintColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/> |
180 | <connections> | 173 | <connections> |
181 | <action selector="segmentValueChange:" destination="-1" eventType="valueChanged" id="kL2-mI-baG"/> | 174 | <action selector="segmentValueChange:" destination="-1" eventType="valueChanged" id="kL2-mI-baG"/> |
182 | </connections> | 175 | </connections> |
183 | </segmentedControl> | 176 | </segmentedControl> |
184 | <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kdD-rj-BtX" userLabel="tvNotice"> | 177 | <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kdD-rj-BtX" userLabel="tvNotice"> |
185 | <rect key="frame" x="103" y="313" width="264" height="204"/> | 178 | <rect key="frame" x="8" y="313" width="359" height="204"/> |
186 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | 179 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> |
187 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | 180 | <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/> |
188 | <fontDescription key="fontDescription" type="system" pointSize="14"/> | 181 | <fontDescription key="fontDescription" type="system" pointSize="17"/> |
189 | <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> | 182 | <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> |
190 | </textView> | 183 | </textView> |
191 | </subviews> | 184 | </subviews> |
192 | <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> | 185 | <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> |
193 | <constraints> | 186 | <constraints> |
194 | <constraint firstItem="IaR-IO-4RA" firstAttribute="leading" secondItem="vRa-cr-YTe" secondAttribute="trailing" constant="8" id="010-mM-SLU"/> | 187 | <constraint firstItem="IaR-IO-4RA" firstAttribute="leading" secondItem="vRa-cr-YTe" secondAttribute="trailing" constant="8" id="010-mM-SLU"/> |
195 | <constraint firstAttribute="trailing" secondItem="Low-8n-pqa" secondAttribute="trailing" constant="10" id="0OY-h0-Rgg"/> | 188 | <constraint firstAttribute="trailing" secondItem="Low-8n-pqa" secondAttribute="trailing" constant="10" id="0OY-h0-Rgg"/> |
196 | <constraint firstAttribute="trailing" secondItem="kdD-rj-BtX" secondAttribute="trailing" constant="8" id="3bP-sY-1pI"/> | 189 | <constraint firstAttribute="trailing" secondItem="kdD-rj-BtX" secondAttribute="trailing" constant="8" id="3bP-sY-1pI"/> |
197 | <constraint firstItem="u3S-9u-GMZ" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="4TN-aJ-vQh"/> | 190 | <constraint firstItem="u3S-9u-GMZ" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="4TN-aJ-vQh"/> |
198 | <constraint firstAttribute="trailing" secondItem="u3S-9u-GMZ" secondAttribute="trailing" id="8KH-Mn-IUf"/> | 191 | <constraint firstAttribute="trailing" secondItem="u3S-9u-GMZ" secondAttribute="trailing" id="8KH-Mn-IUf"/> |
199 | <constraint firstItem="DuE-Dh-nEe" firstAttribute="top" secondItem="3Xj-IB-96h" secondAttribute="bottom" constant="8" id="9h2-XH-Dd7"/> | 192 | <constraint firstItem="DuE-Dh-nEe" firstAttribute="top" secondItem="3Xj-IB-96h" secondAttribute="bottom" constant="8" id="9h2-XH-Dd7"/> |
200 | <constraint firstItem="kdD-rj-BtX" firstAttribute="top" secondItem="lnt-4H-Ao8" secondAttribute="bottom" constant="8" id="BCi-jo-C0A"/> | 193 | <constraint firstItem="kdD-rj-BtX" firstAttribute="top" secondItem="lnt-4H-Ao8" secondAttribute="bottom" constant="8" id="BCi-jo-C0A"/> |
201 | <constraint firstAttribute="trailing" secondItem="LPY-Zl-cOp" secondAttribute="trailing" constant="10" id="CX3-BL-hNh"/> | 194 | <constraint firstAttribute="trailing" secondItem="LPY-Zl-cOp" secondAttribute="trailing" constant="10" id="CX3-BL-hNh"/> |
202 | <constraint firstItem="vRa-cr-YTe" firstAttribute="leading" secondItem="J2A-tf-wH0" secondAttribute="trailing" constant="10" id="Cax-pu-Kp7"/> | 195 | <constraint firstItem="vRa-cr-YTe" firstAttribute="leading" secondItem="J2A-tf-wH0" secondAttribute="trailing" constant="10" id="Cax-pu-Kp7"/> |
203 | <constraint firstItem="3Xj-IB-96h" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="E8R-qO-PtJ"/> | 196 | <constraint firstItem="3Xj-IB-96h" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="E8R-qO-PtJ"/> |
204 | <constraint firstItem="kdD-rj-BtX" firstAttribute="leading" secondItem="BoP-c1-c0q" secondAttribute="trailing" constant="8" id="EE0-bp-sbO"/> | ||
205 | <constraint firstItem="b6V-Bi-4oz" firstAttribute="centerX" secondItem="vRa-cr-YTe" secondAttribute="centerX" id="EEt-Ct-vxb"/> | 197 | <constraint firstItem="b6V-Bi-4oz" firstAttribute="centerX" secondItem="vRa-cr-YTe" secondAttribute="centerX" id="EEt-Ct-vxb"/> |
206 | <constraint firstItem="u3S-9u-GMZ" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" placeholder="YES" id="GbN-me-UEd"/> | 198 | <constraint firstItem="u3S-9u-GMZ" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" placeholder="YES" id="GbN-me-UEd"/> |
207 | <constraint firstItem="b6V-Bi-4oz" firstAttribute="centerY" secondItem="vRa-cr-YTe" secondAttribute="centerY" id="HXS-oH-EPB"/> | 199 | <constraint firstItem="b6V-Bi-4oz" firstAttribute="centerY" secondItem="vRa-cr-YTe" secondAttribute="centerY" id="HXS-oH-EPB"/> |
208 | <constraint firstItem="vRa-cr-YTe" firstAttribute="centerY" secondItem="J2A-tf-wH0" secondAttribute="centerY" id="IDF-HZ-fqt"/> | 200 | <constraint firstItem="vRa-cr-YTe" firstAttribute="centerY" secondItem="J2A-tf-wH0" secondAttribute="centerY" id="IDF-HZ-fqt"/> |
209 | <constraint firstAttribute="trailing" secondItem="lnt-4H-Ao8" secondAttribute="trailing" constant="8" id="IEA-1V-AZx"/> | 201 | <constraint firstAttribute="trailing" secondItem="lnt-4H-Ao8" secondAttribute="trailing" constant="8" id="IEA-1V-AZx"/> |
210 | <constraint firstItem="ibb-Yl-iqu" firstAttribute="top" secondItem="VAz-hq-dvR" secondAttribute="bottom" constant="20" id="Ib2-KY-3A7"/> | 202 | <constraint firstItem="ibb-Yl-iqu" firstAttribute="top" secondItem="VAz-hq-dvR" secondAttribute="bottom" constant="20" id="Ib2-KY-3A7"/> |
211 | <constraint firstAttribute="bottom" secondItem="ibb-Yl-iqu" secondAttribute="bottom" constant="64" id="Iv8-Al-1Ff"/> | 203 | <constraint firstAttribute="bottom" secondItem="ibb-Yl-iqu" secondAttribute="bottom" constant="64" id="Iv8-Al-1Ff"/> |
212 | <constraint firstItem="BoP-c1-c0q" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="20" id="OVd-PH-Yxx"/> | ||
213 | <constraint firstItem="DuE-Dh-nEe" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="Rum-yc-3Ym"/> | 204 | <constraint firstItem="DuE-Dh-nEe" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="Rum-yc-3Ym"/> |
214 | <constraint firstItem="Low-8n-pqa" firstAttribute="centerY" secondItem="J2A-tf-wH0" secondAttribute="centerY" id="W7b-Hb-9ME"/> | 205 | <constraint firstItem="Low-8n-pqa" firstAttribute="centerY" secondItem="J2A-tf-wH0" secondAttribute="centerY" id="W7b-Hb-9ME"/> |
215 | <constraint firstItem="IaR-IO-4RA" firstAttribute="centerY" secondItem="J2A-tf-wH0" secondAttribute="centerY" id="b4I-Me-4xZ"/> | 206 | <constraint firstItem="IaR-IO-4RA" firstAttribute="centerY" secondItem="J2A-tf-wH0" secondAttribute="centerY" id="b4I-Me-4xZ"/> |
216 | <constraint firstItem="BoP-c1-c0q" firstAttribute="top" secondItem="lnt-4H-Ao8" secondAttribute="bottom" constant="8" id="bAt-3o-b1H"/> | ||
217 | <constraint firstItem="wfu-aB-xXm" firstAttribute="top" secondItem="IaR-IO-4RA" secondAttribute="bottom" constant="40" id="bH1-l5-YRA"/> | 207 | <constraint firstItem="wfu-aB-xXm" firstAttribute="top" secondItem="IaR-IO-4RA" secondAttribute="bottom" constant="40" id="bH1-l5-YRA"/> |
218 | <constraint firstItem="lnt-4H-Ao8" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="ea3-Dx-s4s"/> | 208 | <constraint firstItem="lnt-4H-Ao8" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="ea3-Dx-s4s"/> |
219 | <constraint firstItem="at8-co-gC4" firstAttribute="centerX" secondItem="Low-8n-pqa" secondAttribute="centerX" id="h5o-Cj-Z7s"/> | 209 | <constraint firstItem="at8-co-gC4" firstAttribute="centerX" secondItem="Low-8n-pqa" secondAttribute="centerX" id="h5o-Cj-Z7s"/> |
220 | <constraint firstAttribute="trailing" secondItem="DuE-Dh-nEe" secondAttribute="trailing" constant="8" id="iyi-TY-Wfe"/> | 210 | <constraint firstAttribute="trailing" secondItem="DuE-Dh-nEe" secondAttribute="trailing" constant="8" id="iyi-TY-Wfe"/> |
221 | <constraint firstItem="LPY-Zl-cOp" firstAttribute="centerY" secondItem="u3S-9u-GMZ" secondAttribute="centerY" id="jBf-Ck-YYj"/> | 211 | <constraint firstItem="LPY-Zl-cOp" firstAttribute="centerY" secondItem="u3S-9u-GMZ" secondAttribute="centerY" id="jBf-Ck-YYj"/> |
222 | <constraint firstItem="TUf-Tp-93t" firstAttribute="centerY" secondItem="wfu-aB-xXm" secondAttribute="centerY" constant="-5" id="k3n-lY-8K1"/> | 212 | <constraint firstItem="TUf-Tp-93t" firstAttribute="centerY" secondItem="wfu-aB-xXm" secondAttribute="centerY" constant="-5" id="k3n-lY-8K1"/> |
223 | <constraint firstItem="J2A-tf-wH0" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="mVQ-bZ-JBW"/> | 213 | <constraint firstItem="J2A-tf-wH0" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="mVQ-bZ-JBW"/> |
224 | <constraint firstAttribute="trailing" secondItem="wfu-aB-xXm" secondAttribute="trailing" constant="20" id="mtA-2Q-ssH"/> | 214 | <constraint firstAttribute="trailing" secondItem="wfu-aB-xXm" secondAttribute="trailing" constant="20" id="mtA-2Q-ssH"/> |
225 | <constraint firstItem="ibb-Yl-iqu" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="nOT-Ic-JU1"/> | 215 | <constraint firstItem="ibb-Yl-iqu" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="nOT-Ic-JU1"/> |
226 | <constraint firstItem="J2A-tf-wH0" firstAttribute="top" secondItem="u3S-9u-GMZ" secondAttribute="bottom" constant="10" id="nu9-Lj-5xz"/> | 216 | <constraint firstItem="J2A-tf-wH0" firstAttribute="top" secondItem="u3S-9u-GMZ" secondAttribute="bottom" constant="10" id="nu9-Lj-5xz"/> |
227 | <constraint firstAttribute="trailing" secondItem="3Xj-IB-96h" secondAttribute="trailing" constant="8" id="pF6-db-UUi"/> | 217 | <constraint firstAttribute="trailing" secondItem="3Xj-IB-96h" secondAttribute="trailing" constant="8" id="pF6-db-UUi"/> |
228 | <constraint firstItem="3Xj-IB-96h" firstAttribute="top" secondItem="wfu-aB-xXm" secondAttribute="bottom" constant="8" id="psY-0r-fPJ"/> | 218 | <constraint firstItem="3Xj-IB-96h" firstAttribute="top" secondItem="wfu-aB-xXm" secondAttribute="bottom" constant="8" id="psY-0r-fPJ"/> |
219 | <constraint firstItem="kdD-rj-BtX" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="q4Z-No-KmH"/> | ||
229 | <constraint firstItem="TUf-Tp-93t" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="20" id="sC4-Kr-3bN"/> | 220 | <constraint firstItem="TUf-Tp-93t" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="20" id="sC4-Kr-3bN"/> |
230 | <constraint firstItem="at8-co-gC4" firstAttribute="centerY" secondItem="Low-8n-pqa" secondAttribute="centerY" id="tav-ge-tCT"/> | 221 | <constraint firstItem="at8-co-gC4" firstAttribute="centerY" secondItem="Low-8n-pqa" secondAttribute="centerY" id="tav-ge-tCT"/> |
231 | <constraint firstItem="VAz-hq-dvR" firstAttribute="top" secondItem="kdD-rj-BtX" secondAttribute="bottom" constant="8" id="ujL-1z-cUf"/> | 222 | <constraint firstItem="VAz-hq-dvR" firstAttribute="top" secondItem="kdD-rj-BtX" secondAttribute="bottom" constant="8" id="ujL-1z-cUf"/> |
232 | <constraint firstItem="lnt-4H-Ao8" firstAttribute="top" secondItem="DuE-Dh-nEe" secondAttribute="bottom" constant="20" id="w4w-Z4-Jzk"/> | 223 | <constraint firstItem="lnt-4H-Ao8" firstAttribute="top" secondItem="DuE-Dh-nEe" secondAttribute="bottom" constant="20" id="w4w-Z4-Jzk"/> |
233 | <constraint firstItem="wfu-aB-xXm" firstAttribute="leading" secondItem="TUf-Tp-93t" secondAttribute="trailing" constant="10" id="x51-DA-4Le"/> | 224 | <constraint firstItem="wfu-aB-xXm" firstAttribute="leading" secondItem="TUf-Tp-93t" secondAttribute="trailing" constant="10" id="x51-DA-4Le"/> |
234 | <constraint firstItem="VAz-hq-dvR" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="xE7-ro-k8m"/> | 225 | <constraint firstItem="VAz-hq-dvR" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="xE7-ro-k8m"/> |
235 | <constraint firstItem="Low-8n-pqa" firstAttribute="leading" secondItem="IaR-IO-4RA" secondAttribute="trailing" constant="8" id="y6e-6A-hjn"/> | 226 | <constraint firstItem="Low-8n-pqa" firstAttribute="leading" secondItem="IaR-IO-4RA" secondAttribute="trailing" constant="8" id="y6e-6A-hjn"/> |
236 | </constraints> | 227 | </constraints> |
237 | <point key="canvasLocation" x="33.5" y="97.5"/> | 228 | <point key="canvasLocation" x="33.5" y="97.5"/> |
238 | </view> | 229 | </view> |
239 | </objects> | 230 | </objects> |
240 | <resources> | 231 | <resources> |
241 | <image name="avatar_default" width="80" height="80"/> | 232 | <image name="avatar_default" width="80" height="80"/> |
242 | <image name="icon_left" width="30" height="30"/> | 233 | <image name="icon_left" width="30" height="30"/> |
243 | <image name="icon_menu" width="30" height="30"/> | 234 | <image name="icon_menu" width="30" height="30"/> |
244 | <image name="icon_other" width="150" height="134"/> | ||
245 | <image name="icon_right" width="30" height="30"/> | 235 | <image name="icon_right" width="30" height="30"/> |
246 | </resources> | 236 | </resources> |
247 | </document> | 237 | </document> |
LifeLog/LifeLog/Info.plist
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
3 | <plist version="1.0"> | 3 | <plist version="1.0"> |
4 | <dict> | 4 | <dict> |
5 | <key>CFBundleDevelopmentRegion</key> | 5 | <key>CFBundleDevelopmentRegion</key> |
6 | <string>en</string> | 6 | <string>en</string> |
7 | <key>CFBundleDisplayName</key> | 7 | <key>CFBundleDisplayName</key> |
8 | <string>LIFE_LOG</string> | 8 | <string>LIFE_LOG</string> |
9 | <key>CFBundleExecutable</key> | 9 | <key>CFBundleExecutable</key> |
10 | <string>$(EXECUTABLE_NAME)</string> | 10 | <string>$(EXECUTABLE_NAME)</string> |
11 | <key>CFBundleIdentifier</key> | 11 | <key>CFBundleIdentifier</key> |
12 | <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | 12 | <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> |
13 | <key>CFBundleInfoDictionaryVersion</key> | 13 | <key>CFBundleInfoDictionaryVersion</key> |
14 | <string>6.0</string> | 14 | <string>6.0</string> |
15 | <key>CFBundleName</key> | 15 | <key>CFBundleName</key> |
16 | <string>$(PRODUCT_NAME)</string> | 16 | <string>$(PRODUCT_NAME)</string> |
17 | <key>CFBundlePackageType</key> | 17 | <key>CFBundlePackageType</key> |
18 | <string>APPL</string> | 18 | <string>APPL</string> |
19 | <key>CFBundleShortVersionString</key> | 19 | <key>CFBundleShortVersionString</key> |
20 | <string>1.0</string> | 20 | <string>1.0</string> |
21 | <key>CFBundleURLTypes</key> | 21 | <key>CFBundleURLTypes</key> |
22 | <array> | 22 | <array> |
23 | <dict/> | 23 | <dict/> |
24 | </array> | 24 | </array> |
25 | <key>CFBundleVersion</key> | 25 | <key>CFBundleVersion</key> |
26 | <string>4</string> | 26 | <string>5</string> |
27 | <key>LSApplicationQueriesSchemes</key> | 27 | <key>LSApplicationQueriesSchemes</key> |
28 | <array> | 28 | <array> |
29 | <string>line</string> | 29 | <string>line</string> |
30 | </array> | 30 | </array> |
31 | <key>LSRequiresIPhoneOS</key> | 31 | <key>LSRequiresIPhoneOS</key> |
32 | <true/> | 32 | <true/> |
33 | <key>NSAppTransportSecurity</key> | 33 | <key>NSAppTransportSecurity</key> |
34 | <dict> | 34 | <dict> |
35 | <key>NSAllowsArbitraryLoads</key> | 35 | <key>NSAllowsArbitraryLoads</key> |
36 | <true/> | 36 | <true/> |
37 | </dict> | 37 | </dict> |
38 | <key>NSCameraUsageDescription</key> | 38 | <key>NSCameraUsageDescription</key> |
39 | <string>to take photos and video</string> | 39 | <string>to take photos and video</string> |
40 | <key>NSLocationAlwaysUsageDescription</key> | 40 | <key>NSLocationAlwaysUsageDescription</key> |
41 | <string>This application requires location services to work</string> | 41 | <string>This application requires location services to work</string> |
42 | <key>NSLocationWhenInUseUsageDescription</key> | 42 | <key>NSLocationWhenInUseUsageDescription</key> |
43 | <string>This application requires location services to work</string> | 43 | <string>This application requires location services to work</string> |
44 | <key>NSMotionUsageDescription</key> | 44 | <key>NSMotionUsageDescription</key> |
45 | <string>$(PRODUCT_NAME) motion use</string> | 45 | <string>$(PRODUCT_NAME) motion use</string> |
46 | <key>NSPhotoLibraryUsageDescription</key> | 46 | <key>NSPhotoLibraryUsageDescription</key> |
47 | <string>to save photos and videos</string> | 47 | <string>to save photos and videos</string> |
48 | <key>UILaunchStoryboardName</key> | 48 | <key>UILaunchStoryboardName</key> |
49 | <string>LaunchScreen</string> | 49 | <string>LaunchScreen</string> |
50 | <key>UIRequiredDeviceCapabilities</key> | 50 | <key>UIRequiredDeviceCapabilities</key> |
51 | <array> | 51 | <array> |
52 | <string>armv7</string> | 52 | <string>armv7</string> |
53 | </array> | 53 | </array> |
54 | <key>UIStatusBarHidden</key> | 54 | <key>UIStatusBarHidden</key> |
55 | <true/> | 55 | <true/> |
56 | <key>UISupportedInterfaceOrientations</key> | 56 | <key>UISupportedInterfaceOrientations</key> |
57 | <array> | 57 | <array> |
58 | <string>UIInterfaceOrientationPortrait</string> | 58 | <string>UIInterfaceOrientationPortrait</string> |
59 | </array> | 59 | </array> |
60 | <key>UISupportedInterfaceOrientations~ipad</key> | 60 | <key>UISupportedInterfaceOrientations~ipad</key> |
61 | <array> | 61 | <array> |
62 | <string>UIInterfaceOrientationPortrait</string> | 62 | <string>UIInterfaceOrientationPortrait</string> |
63 | <string>UIInterfaceOrientationPortraitUpsideDown</string> | 63 | <string>UIInterfaceOrientationPortraitUpsideDown</string> |
64 | <string>UIInterfaceOrientationLandscapeLeft</string> | 64 | <string>UIInterfaceOrientationLandscapeLeft</string> |
65 | <string>UIInterfaceOrientationLandscapeRight</string> | 65 | <string>UIInterfaceOrientationLandscapeRight</string> |
66 | </array> | 66 | </array> |
67 | <key>UIViewControllerBasedStatusBarAppearance</key> | 67 | <key>UIViewControllerBasedStatusBarAppearance</key> |
68 | <false/> | 68 | <false/> |
69 | </dict> | 69 | </dict> |
70 | </plist> | 70 | </plist> |
71 | 71 |
LifeLog/LifeLog/ServerAPI.h
1 | // | 1 | // |
2 | // ServerAPI.h | 2 | // ServerAPI.h |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by Nguyen Van Phong on 7/30/17. | 5 | // Created by Nguyen Van Phong on 7/30/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import <Foundation/Foundation.h> | 9 | #import <Foundation/Foundation.h> |
10 | #import "Entities.h" | 10 | #import "Entities.h" |
11 | 11 | ||
12 | extern NSString *const kServerAddress; | 12 | extern NSString *const kServerAddress; |
13 | extern NSString *const kUser; | 13 | extern NSString *const kUser; |
14 | extern NSString *const kToken; | 14 | extern NSString *const kToken; |
15 | extern NSString *const kNotificationToken; | 15 | extern NSString *const kNotificationToken; |
16 | 16 | ||
17 | @interface ServerAPI : NSObject | 17 | @interface ServerAPI : NSObject |
18 | + (instancetype) server; | 18 | + (instancetype) server; |
19 | @property (nonatomic, assign) NSTimeInterval timeOutInterval; | 19 | @property (nonatomic, assign) NSTimeInterval timeOutInterval; |
20 | 20 | ||
21 | #pragma mark - Login and Register | 21 | #pragma mark - Login and Register |
22 | - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; | 22 | - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; |
23 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; | 23 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion; |
24 | - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion; | 24 | - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion; |
25 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion; | 25 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion; |
26 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion; | 26 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion; |
27 | 27 | ||
28 | #pragma mark - Home Screen Function | 28 | #pragma mark - Home Screen Function |
29 | - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion; | 29 | - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion; |
30 | - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion; | 30 | - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion; |
31 | - (void)requestHomeWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(HomeObject *, NSError *)) completion; | 31 | - (void)requestHomeWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(HomeObject *, NSError *)) completion; |
32 | 32 | ||
33 | #pragma mark - History Screen Function | 33 | #pragma mark - History Screen Function |
34 | - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 34 | - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
35 | - (void) requestHistoryList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 35 | - (void) requestHistoryList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
36 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion; | 36 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion; |
37 | -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; | 37 | -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; |
38 | - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 38 | - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
39 | 39 | ||
40 | #pragma mark - SNS Screen Function | 40 | #pragma mark - SNS Screen Function |
41 | /* | 41 | /* |
42 | Get tweet of group and get recent tweet is same API | 42 | Get tweet of group and get recent tweet is same API |
43 | If groupID equal -1, it will request recent tweet. Otherwise will request tweet of group | 43 | If groupID equal -1, it will request recent tweet. Otherwise will request tweet of group |
44 | */ | 44 | */ |
45 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 45 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
46 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 46 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
47 | 47 | ||
48 | #pragma mark - Group Function | 48 | #pragma mark - Group Function |
49 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; | 49 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion; |
50 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 50 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
51 | 51 | ||
52 | #pragma mark - Ranking API | 52 | #pragma mark - Ranking API |
53 | - (void) requestRankingList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate mode:(int) mode page:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | 53 | - (void) requestRankingList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate mode:(int) mode page:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; |
54 | 54 | ||
55 | #pragma mark - Common API | 55 | #pragma mark - Common API |
56 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; | 56 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion; |
57 | #pragma mark - Get Notice | ||
58 | - (void)getNoticeByDate: (NSString *)date CompletionHandler:(void (^)(NSArray *, NSError *)) completion; | ||
57 | @end | 59 | @end |
58 | 60 |
LifeLog/LifeLog/ServerAPI.m
1 | // | 1 | // |
2 | // ServerAPI.m | 2 | // ServerAPI.m |
3 | // LifeLog | 3 | // LifeLog |
4 | // | 4 | // |
5 | // Created by Nguyen Van Phong on 7/30/17. | 5 | // Created by Nguyen Van Phong on 7/30/17. |
6 | // Copyright © 2017 PhongNV. All rights reserved. | 6 | // Copyright © 2017 PhongNV. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | #import "ServerAPI.h" | 9 | #import "ServerAPI.h" |
10 | #import "Utilities.h" | 10 | #import "Utilities.h" |
11 | 11 | ||
12 | NSString *const kServerAddress = @"http://clover.timesfun.jp:9001/"; | 12 | NSString *const kServerAddress = @"http://clover.timesfun.jp:9001/"; |
13 | NSString *const kUser = @"KEY_USER"; | 13 | NSString *const kUser = @"KEY_USER"; |
14 | NSString *const kToken = @"KEY_TOKEN"; | 14 | NSString *const kToken = @"KEY_TOKEN"; |
15 | NSString *const kNotificationToken = @"TOKEN_INVALID"; | 15 | NSString *const kNotificationToken = @"TOKEN_INVALID"; |
16 | 16 | ||
17 | @implementation NSString (NSString_Extended) | 17 | @implementation NSString (NSString_Extended) |
18 | - (NSString *)urlencode { | 18 | - (NSString *)urlencode { |
19 | NSMutableString *output = [NSMutableString string]; | 19 | NSMutableString *output = [NSMutableString string]; |
20 | const unsigned char *source = (const unsigned char *)[self UTF8String]; | 20 | const unsigned char *source = (const unsigned char *)[self UTF8String]; |
21 | int sourceLen = (int)strlen((const char *)source); | 21 | int sourceLen = (int)strlen((const char *)source); |
22 | for (int i = 0; i < sourceLen; ++i) { | 22 | for (int i = 0; i < sourceLen; ++i) { |
23 | const unsigned char thisChar = source[i]; | 23 | const unsigned char thisChar = source[i]; |
24 | if (thisChar == ' '){ | 24 | if (thisChar == ' '){ |
25 | [output appendString:@"+"]; | 25 | [output appendString:@"+"]; |
26 | } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' || | 26 | } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' || |
27 | (thisChar >= 'a' && thisChar <= 'z') || | 27 | (thisChar >= 'a' && thisChar <= 'z') || |
28 | (thisChar >= 'A' && thisChar <= 'Z') || | 28 | (thisChar >= 'A' && thisChar <= 'Z') || |
29 | (thisChar >= '0' && thisChar <= '9')) { | 29 | (thisChar >= '0' && thisChar <= '9')) { |
30 | [output appendFormat:@"%c", thisChar]; | 30 | [output appendFormat:@"%c", thisChar]; |
31 | } else { | 31 | } else { |
32 | [output appendFormat:@"%%%02X", thisChar]; | 32 | [output appendFormat:@"%%%02X", thisChar]; |
33 | } | 33 | } |
34 | } | 34 | } |
35 | return output; | 35 | return output; |
36 | } | 36 | } |
37 | @end | 37 | @end |
38 | 38 | ||
39 | @implementation ServerAPI | 39 | @implementation ServerAPI |
40 | static ServerAPI *_server = nil; | 40 | static ServerAPI *_server = nil; |
41 | 41 | ||
42 | NSURLSessionDataTask * searchTask; | 42 | NSURLSessionDataTask * searchTask; |
43 | 43 | ||
44 | @synthesize timeOutInterval = _timeOutInterval; | 44 | @synthesize timeOutInterval = _timeOutInterval; |
45 | 45 | ||
46 | + (instancetype)server | 46 | + (instancetype)server |
47 | { | 47 | { |
48 | @synchronized(self) { | 48 | @synchronized(self) { |
49 | if (_server == nil) { | 49 | if (_server == nil) { |
50 | _server = [[ServerAPI alloc] init]; | 50 | _server = [[ServerAPI alloc] init]; |
51 | } | 51 | } |
52 | } | 52 | } |
53 | return _server; | 53 | return _server; |
54 | } | 54 | } |
55 | 55 | ||
56 | - (instancetype)init | 56 | - (instancetype)init |
57 | { | 57 | { |
58 | self = [super init]; | 58 | self = [super init]; |
59 | if (self != nil) { | 59 | if (self != nil) { |
60 | self.timeOutInterval = 60; | 60 | self.timeOutInterval = 60; |
61 | } | 61 | } |
62 | return self; | 62 | return self; |
63 | } | 63 | } |
64 | 64 | ||
65 | #pragma mark - Login and Register | 65 | #pragma mark - Login and Register |
66 | // Login | 66 | // Login |
67 | - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion | 67 | - (void)loginWithEmail:(NSString *)email Password:(NSString *)password CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion |
68 | { | 68 | { |
69 | [self _request:[kServerAddress stringByAppendingFormat: @"login"] method:@"POST" token:@"" paras:@{@"email":email, @"password": password} completion:^(NSData *data, NSError *error) { | 69 | [self _request:[kServerAddress stringByAppendingFormat: @"login"] method:@"POST" token:@"" paras:@{@"email":email, @"password": password} completion:^(NSData *data, NSError *error) { |
70 | 70 | ||
71 | if (completion == NULL) { | 71 | if (completion == NULL) { |
72 | return ; | 72 | return ; |
73 | } | 73 | } |
74 | 74 | ||
75 | if (error == nil) | 75 | if (error == nil) |
76 | { | 76 | { |
77 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 77 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
78 | 78 | ||
79 | int status = [dataResult[@"status"] intValue]; | 79 | int status = [dataResult[@"status"] intValue]; |
80 | if (status == 1) { // status = 1 success | 80 | if (status == 1) { // status = 1 success |
81 | NSString *token = dataResult[@"result"][@"token"]; | 81 | NSString *token = dataResult[@"result"][@"token"]; |
82 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; | 82 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; |
83 | User *user = [[User alloc] init]; | 83 | User *user = [[User alloc] init]; |
84 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; | 84 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; |
85 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; | 85 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; |
86 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; | 86 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; |
87 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; | 87 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; |
88 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; | 88 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; |
89 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; | 89 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; |
90 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; | 90 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; |
91 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; | 91 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; |
92 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; | 92 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; |
93 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; | 93 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; |
94 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; | 94 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; |
95 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; | 95 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; |
96 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; | 96 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; |
97 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; | 97 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; |
98 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; | 98 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; |
99 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; | 99 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; |
100 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; | 100 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; |
101 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; | 101 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; |
102 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; | 102 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; |
103 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; | 103 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; |
104 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; | 104 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; |
105 | user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; | 105 | user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; |
106 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; | 106 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; |
107 | completion(user, token, nil); | 107 | completion(user, token, nil); |
108 | } | 108 | } |
109 | else { // status = 0 error | 109 | else { // status = 0 error |
110 | NSString *message = dataResult[@"message"]; | 110 | NSString *message = dataResult[@"message"]; |
111 | if (message == nil) { | 111 | if (message == nil) { |
112 | message = @"Unknown error"; | 112 | message = @"Unknown error"; |
113 | } | 113 | } |
114 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 114 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
115 | completion(nil, nil, loginFaild); | 115 | completion(nil, nil, loginFaild); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | else | 118 | else |
119 | { | 119 | { |
120 | completion(nil, nil, error); | 120 | completion(nil, nil, error); |
121 | } | 121 | } |
122 | }]; | 122 | }]; |
123 | } | 123 | } |
124 | 124 | ||
125 | // Register | 125 | // Register |
126 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion { | 126 | - (void)registerUserWithParams:(NSDictionary *)params CompletionHandler: (void (^)(User *, NSString *, NSError *)) completion { |
127 | [self _request:[kServerAddress stringByAppendingFormat: @"register"] method:@"POST" token:@"" paras:params completion:^(NSData *data, NSError *error) { | 127 | [self _request:[kServerAddress stringByAppendingFormat: @"register"] method:@"POST" token:@"" paras:params completion:^(NSData *data, NSError *error) { |
128 | 128 | ||
129 | if (completion == NULL) { | 129 | if (completion == NULL) { |
130 | return ; | 130 | return ; |
131 | } | 131 | } |
132 | 132 | ||
133 | if (error == nil) | 133 | if (error == nil) |
134 | { | 134 | { |
135 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 135 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
136 | 136 | ||
137 | int status = [dataResult[@"status"] intValue]; | 137 | int status = [dataResult[@"status"] intValue]; |
138 | if (status == 1) { // status = 1 success | 138 | if (status == 1) { // status = 1 success |
139 | NSString *token = dataResult[@"result"][@"token"]; | 139 | NSString *token = dataResult[@"result"][@"token"]; |
140 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; | 140 | NSDictionary *dictUser = dataResult[@"result"][@"user"]; |
141 | User *user = [[User alloc] init]; | 141 | User *user = [[User alloc] init]; |
142 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; | 142 | user.user_id = [NSString stringWithFormat:@"%@",dictUser[@"id"]]; |
143 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; | 143 | user.username = [NSString stringWithFormat:@"%@",dictUser[@"username"]]; |
144 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; | 144 | user.full_name = [NSString stringWithFormat:@"%@",dictUser[@"full_name"]]; |
145 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; | 145 | user.nickname = [NSString stringWithFormat:@"%@",dictUser[@"nickname"]]; |
146 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; | 146 | user.email = [NSString stringWithFormat:@"%@",dictUser[@"email"]]; |
147 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; | 147 | user.password = [NSString stringWithFormat:@"%@",dictUser[@"password"]]; |
148 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; | 148 | user.birthday = [NSString stringWithFormat:@"%@",dictUser[@"birthday"]]; |
149 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; | 149 | user.address = [NSString stringWithFormat:@"%@",dictUser[@"address"]]; |
150 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; | 150 | user.gender = [[NSString stringWithFormat:@"%@",dictUser[@"gender"]] intValue]; |
151 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; | 151 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; |
152 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; | 152 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; |
153 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; | 153 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; |
154 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; | 154 | user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; |
155 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; | 155 | user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; |
156 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; | 156 | user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; |
157 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; | 157 | user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; |
158 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; | 158 | user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; |
159 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; | 159 | user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; |
160 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; | 160 | user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; |
161 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; | 161 | user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; |
162 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; | 162 | user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; |
163 | user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; | 163 | user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; |
164 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; | 164 | user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; |
165 | completion(user, token, nil); | 165 | completion(user, token, nil); |
166 | } | 166 | } |
167 | else { // status = 0 error | 167 | else { // status = 0 error |
168 | NSString *message = dataResult[@"message"]; | 168 | NSString *message = dataResult[@"message"]; |
169 | if (message == nil) { | 169 | if (message == nil) { |
170 | message = @"Unknown error"; | 170 | message = @"Unknown error"; |
171 | } | 171 | } |
172 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 172 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
173 | completion(nil, nil, loginFaild); | 173 | completion(nil, nil, loginFaild); |
174 | } | 174 | } |
175 | } | 175 | } |
176 | else | 176 | else |
177 | { | 177 | { |
178 | completion(nil, nil, error); | 178 | completion(nil, nil, error); |
179 | } | 179 | } |
180 | }]; | 180 | }]; |
181 | } | 181 | } |
182 | 182 | ||
183 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion { | 183 | - (void)forgetPass:(NSString *)email CompletionHandler:(void (^)(NSError *)) completion { |
184 | [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass"] method:@"POST" token:@"" paras:@{@"email":email} completion:^(NSData *data, NSError *error) { | 184 | [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass"] method:@"POST" token:@"" paras:@{@"email":email} completion:^(NSData *data, NSError *error) { |
185 | 185 | ||
186 | if (completion == NULL) { | 186 | if (completion == NULL) { |
187 | return ; | 187 | return ; |
188 | } | 188 | } |
189 | 189 | ||
190 | if (error == nil) | 190 | if (error == nil) |
191 | { | 191 | { |
192 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 192 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
193 | 193 | ||
194 | int status = [dataResult[@"status"] intValue]; | 194 | int status = [dataResult[@"status"] intValue]; |
195 | if (status == 1) { // status = 1 success | 195 | if (status == 1) { // status = 1 success |
196 | completion(nil); | 196 | completion(nil); |
197 | } | 197 | } |
198 | else { // status = 0 error | 198 | else { // status = 0 error |
199 | NSString *message = dataResult[@"message"]; | 199 | NSString *message = dataResult[@"message"]; |
200 | if (message == nil) { | 200 | if (message == nil) { |
201 | message = @"Unknown error"; | 201 | message = @"Unknown error"; |
202 | } | 202 | } |
203 | NSError *forgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 203 | NSError *forgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
204 | completion(forgetPass); | 204 | completion(forgetPass); |
205 | } | 205 | } |
206 | } | 206 | } |
207 | else | 207 | else |
208 | { | 208 | { |
209 | completion(error); | 209 | completion(error); |
210 | } | 210 | } |
211 | }]; | 211 | }]; |
212 | } | 212 | } |
213 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion { | 213 | - (void)confirmForgetPass:(NSString *)email withConfirm:(NSString *)confirm CompletionHandler:(void (^)(NSError *)) completion { |
214 | [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass/confirm"] method:@"POST" token:@"" paras:@{@"email":email, @"code_confirm": confirm} completion:^(NSData *data, NSError *error) { | 214 | [self _request:[kServerAddress stringByAppendingFormat: @"forgetPass/confirm"] method:@"POST" token:@"" paras:@{@"email":email, @"code_confirm": confirm} completion:^(NSData *data, NSError *error) { |
215 | 215 | ||
216 | if (completion == NULL) { | 216 | if (completion == NULL) { |
217 | return ; | 217 | return ; |
218 | } | 218 | } |
219 | 219 | ||
220 | if (error == nil) | 220 | if (error == nil) |
221 | { | 221 | { |
222 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 222 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
223 | 223 | ||
224 | int status = [dataResult[@"status"] intValue]; | 224 | int status = [dataResult[@"status"] intValue]; |
225 | if (status == 1) { // status = 1 success | 225 | if (status == 1) { // status = 1 success |
226 | completion(nil); | 226 | completion(nil); |
227 | } | 227 | } |
228 | else { // status = 0 error | 228 | else { // status = 0 error |
229 | NSString *message = dataResult[@"message"]; | 229 | NSString *message = dataResult[@"message"]; |
230 | NSError *confirmForgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 230 | NSError *confirmForgetPass = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
231 | completion(confirmForgetPass); | 231 | completion(confirmForgetPass); |
232 | } | 232 | } |
233 | } | 233 | } |
234 | else | 234 | else |
235 | { | 235 | { |
236 | completion(error); | 236 | completion(error); |
237 | } | 237 | } |
238 | }]; | 238 | }]; |
239 | } | 239 | } |
240 | 240 | ||
241 | - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion { | 241 | - (void)uploadImage:(NSString *)token andImageData:(NSData *)data CompletionHandler:(void (^)(NSString *, NSError *)) completion { |
242 | NSDictionary *dict = nil; | 242 | NSDictionary *dict = nil; |
243 | NSString *base64Encoded = [data base64EncodedStringWithOptions:0]; | 243 | NSString *base64Encoded = [data base64EncodedStringWithOptions:0]; |
244 | if (token != nil) { | 244 | if (token != nil) { |
245 | dict = @{@"token":token, @"img": base64Encoded}; | 245 | dict = @{@"token":token, @"img": base64Encoded}; |
246 | } | 246 | } |
247 | else { | 247 | else { |
248 | dict = @{@"img": base64Encoded}; | 248 | dict = @{@"img": base64Encoded}; |
249 | } | 249 | } |
250 | [self _request:[kServerAddress stringByAppendingFormat: @"upload-image"] method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { | 250 | [self _request:[kServerAddress stringByAppendingFormat: @"upload-image"] method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { |
251 | 251 | ||
252 | if (completion == NULL) { | 252 | if (completion == NULL) { |
253 | return ; | 253 | return ; |
254 | } | 254 | } |
255 | 255 | ||
256 | if (error == nil) | 256 | if (error == nil) |
257 | { | 257 | { |
258 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 258 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
259 | NSString *image_profile = [NSString stringWithFormat:@"%@", dataResult[@"message"]]; | 259 | NSString *image_profile = [NSString stringWithFormat:@"%@", dataResult[@"message"]]; |
260 | completion(image_profile, nil); | 260 | completion(image_profile, nil); |
261 | } | 261 | } |
262 | else | 262 | else |
263 | { | 263 | { |
264 | completion(nil, error); | 264 | completion(nil, error); |
265 | } | 265 | } |
266 | }]; | 266 | }]; |
267 | } | 267 | } |
268 | 268 | ||
269 | -(NSString *) convertIntToString : (int) type { | 269 | -(NSString *) convertIntToString : (int) type { |
270 | switch (type) { | 270 | switch (type) { |
271 | case 1: | 271 | case 1: |
272 | return @"week"; | 272 | return @"week"; |
273 | break; | 273 | break; |
274 | case 2: | 274 | case 2: |
275 | return @"oneMonth"; | 275 | return @"oneMonth"; |
276 | break; | 276 | break; |
277 | case 3: | 277 | case 3: |
278 | return @"threeMonth"; | 278 | return @"threeMonth"; |
279 | break; | 279 | break; |
280 | case 4: | 280 | case 4: |
281 | return @"sixMonth"; | 281 | return @"sixMonth"; |
282 | break; | 282 | break; |
283 | default: | 283 | default: |
284 | return @"today"; | 284 | return @"today"; |
285 | break; | 285 | break; |
286 | } | 286 | } |
287 | } | 287 | } |
288 | 288 | ||
289 | #pragma mark - Home Screen Function | 289 | #pragma mark - Home Screen Function |
290 | - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion | 290 | - (void)requestTopWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(TopObject *, NSError *)) completion |
291 | { | 291 | { |
292 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 292 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
293 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/top/%d/%@", mode, date]; | 293 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/top/%d/%@", mode, date]; |
294 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 294 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
295 | 295 | ||
296 | if (completion == NULL) { | 296 | if (completion == NULL) { |
297 | return ; | 297 | return ; |
298 | } | 298 | } |
299 | 299 | ||
300 | if (error == nil) | 300 | if (error == nil) |
301 | { | 301 | { |
302 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 302 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
303 | int status = [dataResult[@"status"] intValue]; | 303 | int status = [dataResult[@"status"] intValue]; |
304 | if (status == 1) { // status = 1 success | 304 | if (status == 1) { // status = 1 success |
305 | if(dataResult[@"result"] != nil) { | 305 | if(dataResult[@"result"] != nil) { |
306 | NSDictionary * dictResult = dataResult[@"result"]; | 306 | NSDictionary * dictResult = dataResult[@"result"]; |
307 | TopObject *topObject = [[TopObject alloc] init]; | 307 | TopObject *topObject = [[TopObject alloc] init]; |
308 | TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]]; | 308 | TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]]; |
309 | topObject.targetInfor = targetInfor; | 309 | topObject.targetInfor = targetInfor; |
310 | topObject.kcal = [[NSString stringWithFormat:@"%@", dictResult[@"kcal"]] intValue]; | 310 | topObject.kcal = [[NSString stringWithFormat:@"%@", dictResult[@"kcal"]] intValue]; |
311 | topObject.distance = [[NSString stringWithFormat:@"%@", dictResult[@"distance"]] floatValue]; | 311 | topObject.distance = [[NSString stringWithFormat:@"%@", dictResult[@"distance"]] floatValue]; |
312 | topObject.time = [NSString stringWithFormat:@"%@", dictResult[@"time"]]; | 312 | topObject.time = [NSString stringWithFormat:@"%@", dictResult[@"time"]]; |
313 | NSMutableArray *arrayStep = [[NSMutableArray alloc] init]; | 313 | NSMutableArray *arrayStep = [[NSMutableArray alloc] init]; |
314 | NSArray *array = dictResult[@"dataChart"]; | 314 | NSArray *array = dictResult[@"dataChart"]; |
315 | for(NSDictionary *dict in array) { | 315 | for(NSDictionary *dict in array) { |
316 | StepObject *object = [[StepObject alloc] init]; | 316 | StepObject *object = [[StepObject alloc] init]; |
317 | if([dict objectForKey:@"numStep"] != nil) { | 317 | if([dict objectForKey:@"numStep"] != nil) { |
318 | object.step = [dict[@"numStep"] intValue]; | 318 | object.step = [dict[@"numStep"] intValue]; |
319 | } | 319 | } |
320 | if([dict objectForKey:@"hour"] != nil) { | 320 | if([dict objectForKey:@"hour"] != nil) { |
321 | object.hour = [dict[@"hour"] intValue]; | 321 | object.hour = [dict[@"hour"] intValue]; |
322 | } | 322 | } |
323 | switch (mode) { | 323 | switch (mode) { |
324 | case 1: | 324 | case 1: |
325 | object.typeStep = @"walking"; | 325 | object.typeStep = @"walking"; |
326 | break; | 326 | break; |
327 | case 2: | 327 | case 2: |
328 | object.typeStep = @"running"; | 328 | object.typeStep = @"running"; |
329 | break; | 329 | break; |
330 | case 3: | 330 | case 3: |
331 | object.typeStep = @"bike"; | 331 | object.typeStep = @"bike"; |
332 | break; | 332 | break; |
333 | default: | 333 | default: |
334 | break; | 334 | break; |
335 | } | 335 | } |
336 | [arrayStep addObject:object]; | 336 | [arrayStep addObject:object]; |
337 | } | 337 | } |
338 | topObject.dataChart = [[NSMutableArray alloc] initWithArray:arrayStep]; | 338 | topObject.dataChart = [[NSMutableArray alloc] initWithArray:arrayStep]; |
339 | completion(topObject, nil); | 339 | completion(topObject, nil); |
340 | } | 340 | } |
341 | else { | 341 | else { |
342 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 342 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
343 | completion(nil, errorObject); | 343 | completion(nil, errorObject); |
344 | } | 344 | } |
345 | } | 345 | } |
346 | else { | 346 | else { |
347 | NSString *message = dataResult[@"message"]; | 347 | NSString *message = dataResult[@"message"]; |
348 | if (message == nil) { | 348 | if (message == nil) { |
349 | message = @"Unknown error"; | 349 | message = @"Unknown error"; |
350 | } | 350 | } |
351 | 351 | ||
352 | if ([message isEqualToString:@"Token is invalid"]) { | 352 | if ([message isEqualToString:@"Token is invalid"]) { |
353 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 353 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
354 | [self requestTopWithMode:mode andDate:date CompletionHandler:completion]; | 354 | [self requestTopWithMode:mode andDate:date CompletionHandler:completion]; |
355 | } | 355 | } |
356 | else { | 356 | else { |
357 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 357 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
358 | completion(nil, errorObject); | 358 | completion(nil, errorObject); |
359 | } | 359 | } |
360 | } | 360 | } |
361 | } | 361 | } |
362 | else | 362 | else |
363 | { | 363 | { |
364 | completion(nil, error); | 364 | completion(nil, error); |
365 | } | 365 | } |
366 | }]; | 366 | }]; |
367 | } | 367 | } |
368 | 368 | ||
369 | - (void)requestHomeWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(HomeObject *, NSError *)) completion | 369 | - (void)requestHomeWithMode:(int)mode andDate:(NSString *)date CompletionHandler:(void (^)(HomeObject *, NSError *)) completion |
370 | { | 370 | { |
371 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 371 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
372 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/home/%d/%@", mode, date]; | 372 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/home/%d/%@", mode, date]; |
373 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 373 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
374 | 374 | ||
375 | if (completion == NULL) { | 375 | if (completion == NULL) { |
376 | return ; | 376 | return ; |
377 | } | 377 | } |
378 | 378 | ||
379 | if (error == nil) | 379 | if (error == nil) |
380 | { | 380 | { |
381 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 381 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
382 | int status = [dataResult[@"status"] intValue]; | 382 | int status = [dataResult[@"status"] intValue]; |
383 | if (status == 1) { // status = 1 success | 383 | if (status == 1) { // status = 1 success |
384 | if(dataResult[@"result"] != nil) { | 384 | if(dataResult[@"result"] != nil) { |
385 | NSDictionary * dictResult = dataResult[@"result"]; | 385 | NSDictionary * dictResult = dataResult[@"result"]; |
386 | HomeObject *homeObject = [[HomeObject alloc] init]; | 386 | HomeObject *homeObject = [[HomeObject alloc] init]; |
387 | TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]]; | 387 | TargetInfor *targetInfor = [[TargetInfor alloc] initWithData:dictResult[@"targetInf"]]; |
388 | homeObject.targetInfor = targetInfor; | 388 | homeObject.targetInfor = targetInfor; |
389 | NSMutableArray *arrayNotice = [[NSMutableArray alloc] init]; | 389 | NSMutableArray *arrayNotice = [[NSMutableArray alloc] init]; |
390 | NSArray *array = dictResult[@"listNotice"]; | 390 | NSArray *array = dictResult[@"listNotice"]; |
391 | for(NSDictionary *dict in array) { | 391 | for(NSDictionary *dict in array) { |
392 | NoticeInfor *object = [[NoticeInfor alloc] initWithData:dict]; | 392 | NoticeInfor *object = [[NoticeInfor alloc] initWithData:dict]; |
393 | [arrayNotice addObject:object]; | 393 | [arrayNotice addObject:object]; |
394 | } | 394 | } |
395 | homeObject.listNotice = [[NSMutableArray alloc] initWithArray:arrayNotice]; | 395 | homeObject.listNotice = [[NSMutableArray alloc] initWithArray:arrayNotice]; |
396 | completion(homeObject, nil); | 396 | completion(homeObject, nil); |
397 | } | 397 | } |
398 | else { | 398 | else { |
399 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 399 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
400 | completion(nil, errorObject); | 400 | completion(nil, errorObject); |
401 | } | 401 | } |
402 | } | 402 | } |
403 | else { | 403 | else { |
404 | NSString *message = dataResult[@"message"]; | 404 | NSString *message = dataResult[@"message"]; |
405 | if (message == nil) { | 405 | if (message == nil) { |
406 | message = @"Unknown error"; | 406 | message = @"Unknown error"; |
407 | } | 407 | } |
408 | 408 | ||
409 | if ([message isEqualToString:@"Token is invalid"]) { | 409 | if ([message isEqualToString:@"Token is invalid"]) { |
410 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 410 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
411 | [self requestHomeWithMode:mode andDate:date CompletionHandler:completion]; | 411 | [self requestHomeWithMode:mode andDate:date CompletionHandler:completion]; |
412 | } | 412 | } |
413 | else { | 413 | else { |
414 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 414 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
415 | completion(nil, errorObject); | 415 | completion(nil, errorObject); |
416 | } | 416 | } |
417 | } | 417 | } |
418 | } | 418 | } |
419 | else | 419 | else |
420 | { | 420 | { |
421 | completion(nil, error); | 421 | completion(nil, error); |
422 | } | 422 | } |
423 | }]; | 423 | }]; |
424 | } | 424 | } |
425 | 425 | ||
426 | - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion { | 426 | - (void)requestCreateLog:(int)mode withStep:(int)numStep startDate:(NSString *)startDate endDate:(NSString *)endDate CompletionHandler:(void (^)(NSError *))completion { |
427 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; | 427 | NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; |
428 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/createLog"]; | 428 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/createLog"]; |
429 | NSDictionary *dict = @{@"mode": [NSNumber numberWithInt:mode], @"numStep": [NSNumber numberWithInt:numStep], @"startTime": startDate, @"endTime": endDate}; | 429 | NSDictionary *dict = @{@"mode": [NSNumber numberWithInt:mode], @"numStep": [NSNumber numberWithInt:numStep], @"startTime": startDate, @"endTime": endDate}; |
430 | [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { | 430 | [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { |
431 | 431 | ||
432 | if (completion == NULL) { | 432 | if (completion == NULL) { |
433 | return ; | 433 | return ; |
434 | } | 434 | } |
435 | 435 | ||
436 | if (error == nil) | 436 | if (error == nil) |
437 | { | 437 | { |
438 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 438 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
439 | int status = [dataResult[@"status"] intValue]; | 439 | int status = [dataResult[@"status"] intValue]; |
440 | if (status == 1) { // status = 1 success | 440 | if (status == 1) { // status = 1 success |
441 | completion(nil); | 441 | completion(nil); |
442 | } | 442 | } |
443 | else { | 443 | else { |
444 | NSString *message = dataResult[@"message"]; | 444 | NSString *message = dataResult[@"message"]; |
445 | if (message == nil) { | 445 | if (message == nil) { |
446 | message = @"Unknown error"; | 446 | message = @"Unknown error"; |
447 | } | 447 | } |
448 | 448 | ||
449 | if ([message isEqualToString:@"Token is invalid"]) { | 449 | if ([message isEqualToString:@"Token is invalid"]) { |
450 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 450 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
451 | [self requestCreateLog:mode withStep:numStep startDate:startDate endDate:endDate CompletionHandler:completion]; | 451 | [self requestCreateLog:mode withStep:numStep startDate:startDate endDate:endDate CompletionHandler:completion]; |
452 | } | 452 | } |
453 | else { | 453 | else { |
454 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 454 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
455 | completion(errorObject); | 455 | completion(errorObject); |
456 | } | 456 | } |
457 | } | 457 | } |
458 | } | 458 | } |
459 | else | 459 | else |
460 | { | 460 | { |
461 | completion(error); | 461 | completion(error); |
462 | } | 462 | } |
463 | }]; | 463 | }]; |
464 | } | 464 | } |
465 | 465 | ||
466 | #pragma mark - History Screen Function | 466 | #pragma mark - History Screen Function |
467 | - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 467 | - (void) requestHistory:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
468 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/history/%@/%@", [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""]]; | 468 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/history/%@/%@", [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""]]; |
469 | NSLog(@"requestHistory link %@", url); | 469 | NSLog(@"requestHistory link %@", url); |
470 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 470 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
471 | 471 | ||
472 | if (completion == NULL) { | 472 | if (completion == NULL) { |
473 | return ; | 473 | return ; |
474 | } | 474 | } |
475 | 475 | ||
476 | if (error == nil) | 476 | if (error == nil) |
477 | { | 477 | { |
478 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 478 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
479 | NSLog(@"%@", dataResult); | 479 | NSLog(@"%@", dataResult); |
480 | int status = [dataResult[@"status"] intValue]; | 480 | int status = [dataResult[@"status"] intValue]; |
481 | if (status == 1) { // status = 1 success | 481 | if (status == 1) { // status = 1 success |
482 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; | 482 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; |
483 | NSDictionary * arrResult = dataResult[@"result"]; | 483 | NSDictionary * arrResult = dataResult[@"result"]; |
484 | if(arrResult != nil) { | 484 | if(arrResult != nil) { |
485 | /* mode_1: Data for mode walking | 485 | /* mode_1: Data for mode walking |
486 | mode_2: Data for mode running | 486 | mode_2: Data for mode running |
487 | mode_3: Data for mode bike */ | 487 | mode_3: Data for mode bike */ |
488 | NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_3", @"mode_1", @"mode_2", nil]; | 488 | NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_3", @"mode_1", @"mode_2", nil]; |
489 | for(NSString * key in arrayKey) { | 489 | for(NSString * key in arrayKey) { |
490 | NSDictionary *mode = [arrResult objectForKey:key]; | 490 | NSDictionary *mode = [arrResult objectForKey:key]; |
491 | if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) { | 491 | if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) { |
492 | HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode]; | 492 | HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode]; |
493 | [arrayHistory addObject:objectMode]; | 493 | [arrayHistory addObject:objectMode]; |
494 | } | 494 | } |
495 | else { | 495 | else { |
496 | [arrayHistory addObject:[[HistoryObject alloc] init]]; | 496 | [arrayHistory addObject:[[HistoryObject alloc] init]]; |
497 | } | 497 | } |
498 | } | 498 | } |
499 | } | 499 | } |
500 | completion(arrayHistory, nil); | 500 | completion(arrayHistory, nil); |
501 | } | 501 | } |
502 | else { | 502 | else { |
503 | NSString *message = dataResult[@"message"]; | 503 | NSString *message = dataResult[@"message"]; |
504 | if (message == nil) { | 504 | if (message == nil) { |
505 | message = @"Unknown error"; | 505 | message = @"Unknown error"; |
506 | } | 506 | } |
507 | 507 | ||
508 | if ([message isEqualToString:@"Token is invalid"]) { | 508 | if ([message isEqualToString:@"Token is invalid"]) { |
509 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 509 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
510 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 510 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
511 | [self requestHistory:tokenNew startDate:startDate endDate:endDate CompletionHandler:completion]; | 511 | [self requestHistory:tokenNew startDate:startDate endDate:endDate CompletionHandler:completion]; |
512 | } | 512 | } |
513 | else { | 513 | else { |
514 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 514 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
515 | completion(nil, errorObject); | 515 | completion(nil, errorObject); |
516 | } | 516 | } |
517 | } | 517 | } |
518 | } | 518 | } |
519 | else | 519 | else |
520 | { | 520 | { |
521 | completion(nil, error); | 521 | completion(nil, error); |
522 | } | 522 | } |
523 | }]; | 523 | }]; |
524 | } | 524 | } |
525 | 525 | ||
526 | - (void) requestHistoryList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 526 | - (void) requestHistoryList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
527 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/history/detail/%@/%@", [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""]]; | 527 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/history/detail/%@/%@", [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""]]; |
528 | NSLog(@"requestHistoryList link %@", url); | 528 | NSLog(@"requestHistoryList link %@", url); |
529 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 529 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
530 | 530 | ||
531 | if (completion == NULL) { | 531 | if (completion == NULL) { |
532 | return ; | 532 | return ; |
533 | } | 533 | } |
534 | 534 | ||
535 | if (error == nil) | 535 | if (error == nil) |
536 | { | 536 | { |
537 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 537 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
538 | NSLog(@"%@", dataResult); | 538 | NSLog(@"%@", dataResult); |
539 | int status = [dataResult[@"status"] intValue]; | 539 | int status = [dataResult[@"status"] intValue]; |
540 | if (status == 1) { // status = 1 success | 540 | if (status == 1) { // status = 1 success |
541 | if(dataResult[@"result"] != nil) { | 541 | if(dataResult[@"result"] != nil) { |
542 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; | 542 | NSMutableArray * arrayHistory = [[NSMutableArray alloc] init]; |
543 | NSDictionary * arrResult = dataResult[@"result"]; | 543 | NSDictionary * arrResult = dataResult[@"result"]; |
544 | if(arrResult != nil) { | 544 | if(arrResult != nil) { |
545 | /* mode_1: Data for mode walking | 545 | /* mode_1: Data for mode walking |
546 | mode_2: Data for mode running | 546 | mode_2: Data for mode running |
547 | mode_3: Data for mode bike */ | 547 | mode_3: Data for mode bike */ |
548 | NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_3", @"mode_1", @"mode_2", nil]; | 548 | NSArray *arrayKey = [NSArray arrayWithObjects:@"mode_3", @"mode_1", @"mode_2", nil]; |
549 | for(NSString * key in arrayKey) { | 549 | for(NSString * key in arrayKey) { |
550 | NSDictionary *mode = [arrResult objectForKey:key]; | 550 | NSDictionary *mode = [arrResult objectForKey:key]; |
551 | if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) { | 551 | if(![[arrResult objectForKey:key] isKindOfClass:[NSNull class]]) { |
552 | NSMutableArray *array = [[NSMutableArray alloc] init]; | 552 | NSMutableArray *array = [[NSMutableArray alloc] init]; |
553 | for(NSString *key in mode.allKeys) { | 553 | for(NSString *key in mode.allKeys) { |
554 | HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode[key]]; | 554 | HistoryObject * objectMode = [[HistoryObject alloc] initWithData:mode[key]]; |
555 | objectMode.date = [Utilities dateFromString:key withFormat:@"yyyy-MM-dd"]; | 555 | objectMode.date = [Utilities dateFromString:key withFormat:@"yyyy-MM-dd"]; |
556 | [array addObject:objectMode]; | 556 | [array addObject:objectMode]; |
557 | } | 557 | } |
558 | [arrayHistory addObject:array]; | 558 | [arrayHistory addObject:array]; |
559 | } | 559 | } |
560 | else { | 560 | else { |
561 | [arrayHistory addObject:[[NSArray alloc] init]]; | 561 | [arrayHistory addObject:[[NSArray alloc] init]]; |
562 | } | 562 | } |
563 | } | 563 | } |
564 | } | 564 | } |
565 | completion(arrayHistory, nil); | 565 | completion(arrayHistory, nil); |
566 | } | 566 | } |
567 | else { | 567 | else { |
568 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 568 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
569 | completion(nil, errorObject); | 569 | completion(nil, errorObject); |
570 | } | 570 | } |
571 | } | 571 | } |
572 | else { | 572 | else { |
573 | NSString *message = dataResult[@"message"]; | 573 | NSString *message = dataResult[@"message"]; |
574 | if (message == nil) { | 574 | if (message == nil) { |
575 | message = @"Unknown error"; | 575 | message = @"Unknown error"; |
576 | } | 576 | } |
577 | 577 | ||
578 | if ([message isEqualToString:@"Token is invalid"]) { | 578 | if ([message isEqualToString:@"Token is invalid"]) { |
579 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 579 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
580 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 580 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
581 | [self requestHistoryList:tokenNew startDate:startDate endDate:endDate CompletionHandler:completion]; | 581 | [self requestHistoryList:tokenNew startDate:startDate endDate:endDate CompletionHandler:completion]; |
582 | } | 582 | } |
583 | else { | 583 | else { |
584 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 584 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
585 | completion(nil, errorObject); | 585 | completion(nil, errorObject); |
586 | } | 586 | } |
587 | } | 587 | } |
588 | } | 588 | } |
589 | else | 589 | else |
590 | { | 590 | { |
591 | completion(nil, error); | 591 | completion(nil, error); |
592 | } | 592 | } |
593 | }]; | 593 | }]; |
594 | } | 594 | } |
595 | 595 | ||
596 | #pragma mark - SNS Screen Function | 596 | #pragma mark - SNS Screen Function |
597 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 597 | - (void) requestTweetsList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
598 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?page=%d&record=10", page]; | 598 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?page=%d&record=10", page]; |
599 | if(groupID > -1) { | 599 | if(groupID > -1) { |
600 | url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page]; | 600 | url = [kServerAddress stringByAppendingFormat:@"api/tweet/list?group_id=%d&page=%d&record=10", groupID, page]; |
601 | } | 601 | } |
602 | NSLog(@"requestTweetsList link %@", url); | 602 | NSLog(@"requestTweetsList link %@", url); |
603 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 603 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
604 | 604 | ||
605 | if (completion == NULL) { | 605 | if (completion == NULL) { |
606 | return ; | 606 | return ; |
607 | } | 607 | } |
608 | 608 | ||
609 | if (error == nil) | 609 | if (error == nil) |
610 | { | 610 | { |
611 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 611 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
612 | NSLog(@"%@", dataResult); | 612 | NSLog(@"%@", dataResult); |
613 | int status = [dataResult[@"status"] intValue]; | 613 | int status = [dataResult[@"status"] intValue]; |
614 | if (status == 1) { // status = 1 success | 614 | if (status == 1) { // status = 1 success |
615 | if(dataResult[@"result"] != nil) { | 615 | if(dataResult[@"result"] != nil) { |
616 | NSArray * array = dataResult[@"result"]; | 616 | NSArray * array = dataResult[@"result"]; |
617 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; | 617 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; |
618 | for(NSDictionary * dict in array) { | 618 | for(NSDictionary * dict in array) { |
619 | TweetObject * object = [[TweetObject alloc] initWithData:dict]; | 619 | TweetObject * object = [[TweetObject alloc] initWithData:dict]; |
620 | [arrayTweets addObject:object]; | 620 | [arrayTweets addObject:object]; |
621 | } | 621 | } |
622 | completion(arrayTweets, nil); | 622 | completion(arrayTweets, nil); |
623 | } | 623 | } |
624 | else { | 624 | else { |
625 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 625 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
626 | completion(nil, errorObject); | 626 | completion(nil, errorObject); |
627 | } | 627 | } |
628 | } | 628 | } |
629 | else { | 629 | else { |
630 | NSString *message = dataResult[@"message"]; | 630 | NSString *message = dataResult[@"message"]; |
631 | if (message == nil) { | 631 | if (message == nil) { |
632 | message = @"Unknown error"; | 632 | message = @"Unknown error"; |
633 | } | 633 | } |
634 | 634 | ||
635 | if ([message isEqualToString:@"Token is invalid"]) { | 635 | if ([message isEqualToString:@"Token is invalid"]) { |
636 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 636 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
637 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 637 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
638 | [self requestTweetsList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; | 638 | [self requestTweetsList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; |
639 | } | 639 | } |
640 | else { | 640 | else { |
641 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 641 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
642 | completion(nil, errorObject); | 642 | completion(nil, errorObject); |
643 | } | 643 | } |
644 | } | 644 | } |
645 | } | 645 | } |
646 | else | 646 | else |
647 | { | 647 | { |
648 | completion(nil, error); | 648 | completion(nil, error); |
649 | } | 649 | } |
650 | }]; | 650 | }]; |
651 | } | 651 | } |
652 | 652 | ||
653 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 653 | - (void) searchGroup:(NSString *)token withKey:(NSString *)key andPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
654 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/search"]; | 654 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/search"]; |
655 | NSLog(@"searchGroup link %@ page %d", url, page); | 655 | NSLog(@"searchGroup link %@ page %d", url, page); |
656 | if(searchTask != nil) { | 656 | if(searchTask != nil) { |
657 | [searchTask cancel]; | 657 | [searchTask cancel]; |
658 | } | 658 | } |
659 | 659 | ||
660 | searchTask = [self _request:url method:@"POST" token:token paras:@{@"keyword":key, @"page": [NSNumber numberWithInt:page]} completion:^(NSData *data, NSError *error) { | 660 | searchTask = [self _request:url method:@"POST" token:token paras:@{@"keyword":key, @"page": [NSNumber numberWithInt:page]} completion:^(NSData *data, NSError *error) { |
661 | searchTask = nil; | 661 | searchTask = nil; |
662 | if (completion == NULL) { | 662 | if (completion == NULL) { |
663 | return ; | 663 | return ; |
664 | } | 664 | } |
665 | 665 | ||
666 | if (error == nil) | 666 | if (error == nil) |
667 | { | 667 | { |
668 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 668 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
669 | NSLog(@"%@", dataResult); | 669 | NSLog(@"%@", dataResult); |
670 | int status = [dataResult[@"status"] intValue]; | 670 | int status = [dataResult[@"status"] intValue]; |
671 | if (status == 1) { // status = 1 success | 671 | if (status == 1) { // status = 1 success |
672 | if(dataResult[@"result"] != nil) { | 672 | if(dataResult[@"result"] != nil) { |
673 | NSArray * array = dataResult[@"result"]; | 673 | NSArray * array = dataResult[@"result"]; |
674 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; | 674 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; |
675 | for(NSDictionary * dict in array) { | 675 | for(NSDictionary * dict in array) { |
676 | GroupObject * object = [[GroupObject alloc] initWithData:dict]; | 676 | GroupObject * object = [[GroupObject alloc] initWithData:dict]; |
677 | [arrayTweets addObject:object]; | 677 | [arrayTweets addObject:object]; |
678 | } | 678 | } |
679 | completion(arrayTweets, nil); | 679 | completion(arrayTweets, nil); |
680 | } | 680 | } |
681 | else { | 681 | else { |
682 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 682 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
683 | completion(nil, errorObject); | 683 | completion(nil, errorObject); |
684 | } | 684 | } |
685 | } | 685 | } |
686 | else { | 686 | else { |
687 | NSString *message = dataResult[@"message"]; | 687 | NSString *message = dataResult[@"message"]; |
688 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 688 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
689 | completion(nil, errorObject); | 689 | completion(nil, errorObject); |
690 | } | 690 | } |
691 | } | 691 | } |
692 | else | 692 | else |
693 | { | 693 | { |
694 | completion(nil, error); | 694 | completion(nil, error); |
695 | } | 695 | } |
696 | }]; | 696 | }]; |
697 | } | 697 | } |
698 | 698 | ||
699 | #pragma mark - Group Function | 699 | #pragma mark - Group Function |
700 | -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { | 700 | -(void) requestCreateGroup:(NSString *)token withGroup:(GroupObject *)group CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { |
701 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/newGroup"]; | 701 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/newGroup"]; |
702 | NSLog(@"requestCreateGroup link %@", url); | 702 | NSLog(@"requestCreateGroup link %@", url); |
703 | NSDictionary * dict = @{@"group_name":group.name, | 703 | NSDictionary * dict = @{@"group_name":group.name, |
704 | @"goal":group.goal, | 704 | @"goal":group.goal, |
705 | @"walk_mode_active":[NSNumber numberWithBool:group.walkMode], | 705 | @"walk_mode_active":[NSNumber numberWithBool:group.walkMode], |
706 | @"run_mode_active":[NSNumber numberWithBool:group.runMode], | 706 | @"run_mode_active":[NSNumber numberWithBool:group.runMode], |
707 | @"bike_mode_active":[NSNumber numberWithBool:group.bikeMode], | 707 | @"bike_mode_active":[NSNumber numberWithBool:group.bikeMode], |
708 | @"step_mode_active":[NSNumber numberWithBool:group.stepMode], | 708 | @"step_mode_active":[NSNumber numberWithBool:group.stepMode], |
709 | @"gym_mode_active":[NSNumber numberWithBool:group.gymMode], | 709 | @"gym_mode_active":[NSNumber numberWithBool:group.gymMode], |
710 | @"beginer_mode_active":[NSNumber numberWithBool:group.beginMode], | 710 | @"beginer_mode_active":[NSNumber numberWithBool:group.beginMode], |
711 | @"walk_mode_goal":[NSNumber numberWithBool:group.walkGoal], | 711 | @"walk_mode_goal":[NSNumber numberWithBool:group.walkGoal], |
712 | @"run_mode_goal":[NSNumber numberWithBool:group.runGoal], | 712 | @"run_mode_goal":[NSNumber numberWithBool:group.runGoal], |
713 | @"bike_mode_goal":[NSNumber numberWithBool:group.bikeGoal]}; | 713 | @"bike_mode_goal":[NSNumber numberWithBool:group.bikeGoal]}; |
714 | 714 | ||
715 | [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { | 715 | [self _request:url method:@"POST" token:token paras:dict completion:^(NSData *data, NSError *error) { |
716 | 716 | ||
717 | if (completion == NULL) { | 717 | if (completion == NULL) { |
718 | return ; | 718 | return ; |
719 | } | 719 | } |
720 | 720 | ||
721 | if (error == nil) | 721 | if (error == nil) |
722 | { | 722 | { |
723 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 723 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
724 | NSLog(@"%@", dataResult); | 724 | NSLog(@"%@", dataResult); |
725 | int status = [dataResult[@"status"] intValue]; | 725 | int status = [dataResult[@"status"] intValue]; |
726 | if (status == 1) { // status = 1 success | 726 | if (status == 1) { // status = 1 success |
727 | if(dataResult[@"result"] != nil) { | 727 | if(dataResult[@"result"] != nil) { |
728 | NSDictionary * dict = dataResult[@"result"]; | 728 | NSDictionary * dict = dataResult[@"result"]; |
729 | group.groupID = [dict[@"group_id"] intValue]; | 729 | group.groupID = [dict[@"group_id"] intValue]; |
730 | completion(group, nil); | 730 | completion(group, nil); |
731 | } | 731 | } |
732 | else { | 732 | else { |
733 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 733 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
734 | completion(nil, errorObject); | 734 | completion(nil, errorObject); |
735 | } | 735 | } |
736 | } | 736 | } |
737 | else { | 737 | else { |
738 | NSString *message = dataResult[@"message"]; | 738 | NSString *message = dataResult[@"message"]; |
739 | if (message == nil) { | 739 | if (message == nil) { |
740 | message = @"Unknown error"; | 740 | message = @"Unknown error"; |
741 | } | 741 | } |
742 | 742 | ||
743 | if ([message isEqualToString:@"Token is invalid"]) { | 743 | if ([message isEqualToString:@"Token is invalid"]) { |
744 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 744 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
745 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 745 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
746 | [self requestCreateGroup:tokenNew withGroup:group CompletionHandler:completion]; | 746 | [self requestCreateGroup:tokenNew withGroup:group CompletionHandler:completion]; |
747 | } | 747 | } |
748 | else { | 748 | else { |
749 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 749 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
750 | completion(nil, errorObject); | 750 | completion(nil, errorObject); |
751 | } | 751 | } |
752 | } | 752 | } |
753 | } | 753 | } |
754 | else | 754 | else |
755 | { | 755 | { |
756 | completion(nil, error); | 756 | completion(nil, error); |
757 | } | 757 | } |
758 | }]; | 758 | }]; |
759 | } | 759 | } |
760 | 760 | ||
761 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { | 761 | - (void) getGroupDetail:(NSString *)token withGroupID:(int)groupID CompletionHandler:(void (^)(GroupObject *, NSError *)) completion { |
762 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/detail/%d", groupID]; | 762 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/detail/%d", groupID]; |
763 | NSLog(@"getGroupDetail link %@", url); | 763 | NSLog(@"getGroupDetail link %@", url); |
764 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 764 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
765 | 765 | ||
766 | if (completion == NULL) { | 766 | if (completion == NULL) { |
767 | return ; | 767 | return ; |
768 | } | 768 | } |
769 | 769 | ||
770 | if (error == nil) | 770 | if (error == nil) |
771 | { | 771 | { |
772 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 772 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
773 | NSLog(@"%@", dataResult); | 773 | NSLog(@"%@", dataResult); |
774 | int status = [dataResult[@"status"] intValue]; | 774 | int status = [dataResult[@"status"] intValue]; |
775 | if (status == 1) { // status = 1 success | 775 | if (status == 1) { // status = 1 success |
776 | if(dataResult[@"result"] != nil) { | 776 | if(dataResult[@"result"] != nil) { |
777 | NSArray * array = dataResult[@"result"]; | 777 | NSArray * array = dataResult[@"result"]; |
778 | GroupObject * object = [[GroupObject alloc] initWithData:array[0] andGroupID:groupID]; | 778 | GroupObject * object = [[GroupObject alloc] initWithData:array[0] andGroupID:groupID]; |
779 | completion(object, nil); | 779 | completion(object, nil); |
780 | } | 780 | } |
781 | else { | 781 | else { |
782 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 782 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
783 | completion(nil, errorObject); | 783 | completion(nil, errorObject); |
784 | } | 784 | } |
785 | } | 785 | } |
786 | else { | 786 | else { |
787 | NSString *message = dataResult[@"message"]; | 787 | NSString *message = dataResult[@"message"]; |
788 | if (message == nil) { | 788 | if (message == nil) { |
789 | message = @"Unknown error"; | 789 | message = @"Unknown error"; |
790 | } | 790 | } |
791 | 791 | ||
792 | if ([message isEqualToString:@"Token is invalid"]) { | 792 | if ([message isEqualToString:@"Token is invalid"]) { |
793 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 793 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
794 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 794 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
795 | [self getGroupDetail:tokenNew withGroupID:groupID CompletionHandler:completion]; | 795 | [self getGroupDetail:tokenNew withGroupID:groupID CompletionHandler:completion]; |
796 | } | 796 | } |
797 | else { | 797 | else { |
798 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 798 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
799 | completion(nil, errorObject); | 799 | completion(nil, errorObject); |
800 | } | 800 | } |
801 | } | 801 | } |
802 | } | 802 | } |
803 | else | 803 | else |
804 | { | 804 | { |
805 | completion(nil, error); | 805 | completion(nil, error); |
806 | } | 806 | } |
807 | }]; | 807 | }]; |
808 | } | 808 | } |
809 | 809 | ||
810 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 810 | - (void) requestMemberList:(NSString *)token groupID: (int) groupID withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
811 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/member/%d/%d", groupID, page]; | 811 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/member/%d/%d", groupID, page]; |
812 | NSLog(@"requestMemberList link %@ page %d", url, page); | 812 | NSLog(@"requestMemberList link %@ page %d", url, page); |
813 | 813 | ||
814 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 814 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
815 | if (completion == NULL) { | 815 | if (completion == NULL) { |
816 | return ; | 816 | return ; |
817 | } | 817 | } |
818 | 818 | ||
819 | if (error == nil) | 819 | if (error == nil) |
820 | { | 820 | { |
821 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 821 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
822 | NSLog(@"%@", dataResult); | 822 | NSLog(@"%@", dataResult); |
823 | int status = [dataResult[@"status"] intValue]; | 823 | int status = [dataResult[@"status"] intValue]; |
824 | if (status == 1) { // status = 1 success | 824 | if (status == 1) { // status = 1 success |
825 | if(dataResult[@"result"] != nil) { | 825 | if(dataResult[@"result"] != nil) { |
826 | NSArray * array = dataResult[@"result"]; | 826 | NSArray * array = dataResult[@"result"]; |
827 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; | 827 | NSMutableArray * arrayTweets = [[NSMutableArray alloc] init]; |
828 | for(NSDictionary * dict in array) { | 828 | for(NSDictionary * dict in array) { |
829 | MemberObject * object = [[MemberObject alloc] initWithData:dict]; | 829 | MemberObject * object = [[MemberObject alloc] initWithData:dict]; |
830 | [arrayTweets addObject:object]; | 830 | [arrayTweets addObject:object]; |
831 | } | 831 | } |
832 | completion(arrayTweets, nil); | 832 | completion(arrayTweets, nil); |
833 | } | 833 | } |
834 | else { | 834 | else { |
835 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 835 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
836 | completion(nil, errorObject); | 836 | completion(nil, errorObject); |
837 | } | 837 | } |
838 | } | 838 | } |
839 | else { | 839 | else { |
840 | NSString *message = dataResult[@"message"]; | 840 | NSString *message = dataResult[@"message"]; |
841 | if (message == nil) { | 841 | if (message == nil) { |
842 | message = @"Unknown error"; | 842 | message = @"Unknown error"; |
843 | } | 843 | } |
844 | 844 | ||
845 | if ([message isEqualToString:@"Token is invalid"]) { | 845 | if ([message isEqualToString:@"Token is invalid"]) { |
846 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 846 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
847 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 847 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
848 | [self requestMemberList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; | 848 | [self requestMemberList:tokenNew groupID:groupID withPage:page CompletionHandler:completion]; |
849 | } | 849 | } |
850 | else { | 850 | else { |
851 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 851 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
852 | completion(nil, errorObject); | 852 | completion(nil, errorObject); |
853 | } | 853 | } |
854 | } | 854 | } |
855 | } | 855 | } |
856 | else | 856 | else |
857 | { | 857 | { |
858 | completion(nil, error); | 858 | completion(nil, error); |
859 | } | 859 | } |
860 | }]; | 860 | }]; |
861 | } | 861 | } |
862 | 862 | ||
863 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion { | 863 | - (void) requestJoinGroup:(NSString *)token groupID: (int) groupID CompletionHandler:(void (^)(NSError *)) completion { |
864 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/join"]; | 864 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/sns/group/join"]; |
865 | NSLog(@"requestJoinGroup link %@", url); | 865 | NSLog(@"requestJoinGroup link %@", url); |
866 | 866 | ||
867 | [self _request:url method:@"POST" token:token paras:@{@"group_id": [NSNumber numberWithInt:groupID]} completion:^(NSData *data, NSError *error) { | 867 | [self _request:url method:@"POST" token:token paras:@{@"group_id": [NSNumber numberWithInt:groupID]} completion:^(NSData *data, NSError *error) { |
868 | if (completion == NULL) { | 868 | if (completion == NULL) { |
869 | return ; | 869 | return ; |
870 | } | 870 | } |
871 | 871 | ||
872 | if (error == nil) | 872 | if (error == nil) |
873 | { | 873 | { |
874 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 874 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
875 | NSLog(@"%@", dataResult); | 875 | NSLog(@"%@", dataResult); |
876 | int status = [dataResult[@"status"] intValue]; | 876 | int status = [dataResult[@"status"] intValue]; |
877 | if (status == 1) { // status = 1 success | 877 | if (status == 1) { // status = 1 success |
878 | if(dataResult[@"result"] != nil) { | 878 | if(dataResult[@"result"] != nil) { |
879 | completion(nil); | 879 | completion(nil); |
880 | } | 880 | } |
881 | else { | 881 | else { |
882 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 882 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
883 | completion(errorObject); | 883 | completion(errorObject); |
884 | } | 884 | } |
885 | } | 885 | } |
886 | else { | 886 | else { |
887 | NSString *message = dataResult[@"message"]; | 887 | NSString *message = dataResult[@"message"]; |
888 | if ([message isEqualToString:@"Token is invalid"]) { | 888 | if ([message isEqualToString:@"Token is invalid"]) { |
889 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 889 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
890 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 890 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
891 | [self requestJoinGroup:tokenNew groupID:groupID CompletionHandler:completion]; | 891 | [self requestJoinGroup:tokenNew groupID:groupID CompletionHandler:completion]; |
892 | } | 892 | } |
893 | else { | 893 | else { |
894 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 894 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
895 | completion(errorObject); | 895 | completion(errorObject); |
896 | } | 896 | } |
897 | } | 897 | } |
898 | } | 898 | } |
899 | else | 899 | else |
900 | { | 900 | { |
901 | completion(error); | 901 | completion(error); |
902 | } | 902 | } |
903 | }]; | 903 | }]; |
904 | } | 904 | } |
905 | 905 | ||
906 | - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 906 | - (void) requestGroupList:(NSString *)token CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
907 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/list"]; | 907 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/groups/list"]; |
908 | NSLog(@"requestGroupList link %@", url); | 908 | NSLog(@"requestGroupList link %@", url); |
909 | 909 | ||
910 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 910 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
911 | if (completion == NULL) { | 911 | if (completion == NULL) { |
912 | return ; | 912 | return ; |
913 | } | 913 | } |
914 | 914 | ||
915 | if (error == nil) | 915 | if (error == nil) |
916 | { | 916 | { |
917 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 917 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
918 | NSLog(@"%@", dataResult); | 918 | NSLog(@"%@", dataResult); |
919 | int status = [dataResult[@"status"] intValue]; | 919 | int status = [dataResult[@"status"] intValue]; |
920 | if (status == 1) { // status = 1 success | 920 | if (status == 1) { // status = 1 success |
921 | if(dataResult[@"result"] != nil) { | 921 | if(dataResult[@"result"] != nil) { |
922 | NSArray * array = dataResult[@"result"]; | 922 | NSArray * array = dataResult[@"result"]; |
923 | NSMutableArray * arrayGroup = [[NSMutableArray alloc] init]; | 923 | NSMutableArray * arrayGroup = [[NSMutableArray alloc] init]; |
924 | for(NSDictionary * dict in array) { | 924 | for(NSDictionary * dict in array) { |
925 | GroupObject * object = [[GroupObject alloc] initWithShortData:dict]; | 925 | GroupObject * object = [[GroupObject alloc] initWithShortData:dict]; |
926 | [arrayGroup addObject:object]; | 926 | [arrayGroup addObject:object]; |
927 | } | 927 | } |
928 | completion(arrayGroup, nil); | 928 | completion(arrayGroup, nil); |
929 | } | 929 | } |
930 | else { | 930 | else { |
931 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 931 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
932 | completion(nil, errorObject); | 932 | completion(nil, errorObject); |
933 | } | 933 | } |
934 | } | 934 | } |
935 | else { | 935 | else { |
936 | NSString *message = dataResult[@"message"]; | 936 | NSString *message = dataResult[@"message"]; |
937 | if (message == nil) { | 937 | if (message == nil) { |
938 | message = @"Unknown error"; | 938 | message = @"Unknown error"; |
939 | } | 939 | } |
940 | 940 | ||
941 | if ([message isEqualToString:@"Token is invalid"]) { | 941 | if ([message isEqualToString:@"Token is invalid"]) { |
942 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 942 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
943 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 943 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
944 | [self requestGroupList:tokenNew CompletionHandler:completion]; | 944 | [self requestGroupList:tokenNew CompletionHandler:completion]; |
945 | } | 945 | } |
946 | else { | 946 | else { |
947 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 947 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
948 | completion(nil, errorObject); | 948 | completion(nil, errorObject); |
949 | } | 949 | } |
950 | } | 950 | } |
951 | } | 951 | } |
952 | else | 952 | else |
953 | { | 953 | { |
954 | completion(nil, error); | 954 | completion(nil, error); |
955 | } | 955 | } |
956 | }]; | 956 | }]; |
957 | } | 957 | } |
958 | 958 | ||
959 | #pragma mark - Ranking API | 959 | #pragma mark - Ranking API |
960 | - (void) requestRankingList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate mode:(int) mode page:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { | 960 | - (void) requestRankingList:(NSString *)token startDate:(NSDate *)startDate endDate:(NSDate *)endDate mode:(int) mode page:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion { |
961 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/ranking/%d/%@/%@/%d", mode, [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""], page]; | 961 | NSString *url = [kServerAddress stringByAppendingFormat:@"api/ranking/%d/%@/%@/%d", mode, [Utilities stringFromDate:startDate withFormat:@"YYYYMMdd" locale:@""], [Utilities stringFromDate:endDate withFormat:@"YYYYMMdd" locale:@""], page]; |
962 | NSLog(@"requestRaningList link %@", url); | 962 | NSLog(@"requestRaningList link %@", url); |
963 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { | 963 | [self _request:url method:@"GET" token:token paras:nil completion:^(NSData *data, NSError *error) { |
964 | 964 | ||
965 | if (completion == NULL) { | 965 | if (completion == NULL) { |
966 | return ; | 966 | return ; |
967 | } | 967 | } |
968 | 968 | ||
969 | if (error == nil) | 969 | if (error == nil) |
970 | { | 970 | { |
971 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 971 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
972 | NSLog(@"%@", dataResult); | 972 | NSLog(@"%@", dataResult); |
973 | int status = [dataResult[@"status"] intValue]; | 973 | int status = [dataResult[@"status"] intValue]; |
974 | if (status == 1) { // status = 1 success | 974 | if (status == 1) { // status = 1 success |
975 | NSArray * array = dataResult[@"result"]; | 975 | NSArray * array = dataResult[@"result"]; |
976 | NSMutableArray * arrayRanking = [[NSMutableArray alloc] init]; | 976 | NSMutableArray * arrayRanking = [[NSMutableArray alloc] init]; |
977 | for(NSDictionary * dict in array) { | 977 | for(NSDictionary * dict in array) { |
978 | RankingObject * object = [[RankingObject alloc] initWithData:dict]; | 978 | RankingObject * object = [[RankingObject alloc] initWithData:dict]; |
979 | [arrayRanking addObject:object]; | 979 | [arrayRanking addObject:object]; |
980 | } | 980 | } |
981 | completion(arrayRanking, nil); | 981 | completion(arrayRanking, nil); |
982 | } | 982 | } |
983 | else { | 983 | else { |
984 | NSString *message = dataResult[@"message"]; | 984 | NSString *message = dataResult[@"message"]; |
985 | if (message == nil) { | 985 | if (message == nil) { |
986 | message = @"Unknown error"; | 986 | message = @"Unknown error"; |
987 | } | 987 | } |
988 | 988 | ||
989 | if ([message isEqualToString:@"Token is invalid"]) { | 989 | if ([message isEqualToString:@"Token is invalid"]) { |
990 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; | 990 | [self performSelectorOnMainThread:@selector(checkToken) withObject:nil waitUntilDone:YES]; |
991 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; | 991 | NSString *tokenNew = [[NSUserDefaults standardUserDefaults] objectForKey:kToken]; |
992 | [self requestRankingList:tokenNew startDate:startDate endDate:endDate mode:mode page:page CompletionHandler:completion]; | 992 | [self requestRankingList:tokenNew startDate:startDate endDate:endDate mode:mode page:page CompletionHandler:completion]; |
993 | } | 993 | } |
994 | else { | 994 | else { |
995 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 995 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
996 | completion(nil, errorObject); | 996 | completion(nil, errorObject); |
997 | } | 997 | } |
998 | } | 998 | } |
999 | } | 999 | } |
1000 | else | 1000 | else |
1001 | { | 1001 | { |
1002 | completion(nil, error); | 1002 | completion(nil, error); |
1003 | } | 1003 | } |
1004 | }]; | 1004 | }]; |
1005 | } | 1005 | } |
1006 | 1006 | ||
1007 | #pragma mark - Common API | 1007 | #pragma mark - Common API |
1008 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { | 1008 | - (void)refreshToken: (NSString *)userID CompletionHandler:(void (^)(NSString *, NSError *))completion { |
1009 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { | 1009 | [self _request:[kServerAddress stringByAppendingFormat: @"refreshToken"] method:@"POST" token:@"" paras:@{@"userId":userID} completion:^(NSData *data, NSError *error) { |
1010 | 1010 | ||
1011 | if (completion == NULL) { | 1011 | if (completion == NULL) { |
1012 | return ; | 1012 | return ; |
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | if (error == nil) | 1015 | if (error == nil) |
1016 | { | 1016 | { |
1017 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | 1017 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; |
1018 | 1018 | ||
1019 | int status = [dataResult[@"status"] intValue]; | 1019 | int status = [dataResult[@"status"] intValue]; |
1020 | if (status == 1) { // status = 1 success | 1020 | if (status == 1) { // status = 1 success |
1021 | NSArray *arrayResult = dataResult[@"result"]; | 1021 | NSArray *arrayResult = dataResult[@"result"]; |
1022 | if (arrayResult.count > 0) { | 1022 | if (arrayResult.count > 0) { |
1023 | NSString *token = arrayResult[0]; | 1023 | NSString *token = arrayResult[0]; |
1024 | completion(token, nil); | 1024 | completion(token, nil); |
1025 | } | 1025 | } |
1026 | else { | 1026 | else { |
1027 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; | 1027 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Unknown Error"}]; |
1028 | completion(nil, errorObject); | 1028 | completion(nil, errorObject); |
1029 | } | 1029 | } |
1030 | 1030 | ||
1031 | } | 1031 | } |
1032 | else { // status = 0 error | 1032 | else { // status = 0 error |
1033 | NSString *message = dataResult[@"message"]; | 1033 | NSString *message = dataResult[@"message"]; |
1034 | if (message == nil) { | 1034 | if (message == nil) { |
1035 | message = @"Unknown error"; | 1035 | message = @"Unknown error"; |
1036 | } | 1036 | } |
1037 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | 1037 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; |
1038 | completion(nil, loginFaild); | 1038 | completion(nil, loginFaild); |
1039 | } | 1039 | } |
1040 | } | 1040 | } |
1041 | else | 1041 | else |
1042 | { | 1042 | { |
1043 | completion(nil, error); | 1043 | completion(nil, error); |
1044 | } | 1044 | } |
1045 | }]; | 1045 | }]; |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | - (void)getNoticeByDate: (NSString *)date CompletionHandler:(void (^)(NSArray *, NSError *)) completion | ||
1049 | { | ||
1050 | [self _request:[kServerAddress stringByAppendingFormat: @"api/getnoticesbydate/%@", date] method:@"GET" token:@"" paras:nil completion:^(NSData *data, NSError *error) { | ||
1051 | |||
1052 | if (completion == NULL) { | ||
1053 | return ; | ||
1054 | } | ||
1055 | |||
1056 | if (error == nil) | ||
1057 | { | ||
1058 | NSDictionary *dataResult = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error: &error]; | ||
1059 | |||
1060 | int status = [dataResult[@"status"] intValue]; | ||
1061 | if (status == 1) { // status = 1 success | ||
1062 | NSArray *arrayResult = dataResult[@"result"][@"listNotice"]; | ||
1063 | if (arrayResult.count > 0) { | ||
1064 | NSMutableArray *notices = [[NSMutableArray alloc] init]; | ||
1065 | for(NSDictionary *dict in arrayResult) { | ||
1066 | NSString *object = [dict objectForKey:@"notice_content"]; | ||
1067 | [notices addObject:object]; | ||
1068 | } | ||
1069 | completion(notices, nil); | ||
1070 | } | ||
1071 | else { | ||
1072 | NSError *errorObject = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":@"Today is not notice"}]; | ||
1073 | completion(nil, errorObject); | ||
1074 | } | ||
1075 | |||
1076 | } | ||
1077 | else { // status = 0 error | ||
1078 | NSString *message = dataResult[@"message"]; | ||
1079 | if (message == nil) { | ||
1080 | message = @"Unknown error"; | ||
1081 | } | ||
1082 | NSError *loginFaild = [NSError errorWithDomain:@"LifeLog_Domain" code:-1 userInfo:@{@"message":message}]; | ||
1083 | completion(nil, loginFaild); | ||
1084 | } | ||
1085 | } | ||
1086 | else | ||
1087 | { | ||
1088 | completion(nil, error); | ||
1089 | } | ||
1090 | }]; | ||
1091 | } | ||
1092 | |||
1048 | #pragma mark - Private Function | 1093 | #pragma mark - Private Function |
1049 | - (void) checkToken { | 1094 | - (void) checkToken { |
1050 | // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; | 1095 | // [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationToken object:nil]; |
1051 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; | 1096 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; |
1052 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; | 1097 | User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; |
1053 | if (user != nil) { | 1098 | if (user != nil) { |
1054 | [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) { | 1099 | [self refreshToken:user.user_id CompletionHandler:^(NSString *token, NSError *error) { |
1055 | if (error == nil) { | 1100 | if (error == nil) { |
1056 | [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; | 1101 | [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; |
1057 | [[NSUserDefaults standardUserDefaults] synchronize]; | 1102 | [[NSUserDefaults standardUserDefaults] synchronize]; |
1058 | } | 1103 | } |
1059 | }]; | 1104 | }]; |
1060 | } | 1105 | } |
1061 | } | 1106 | } |
1062 | - (NSData *) _encodeDictionary: (NSDictionary *) dictionary | 1107 | - (NSData *) _encodeDictionary: (NSDictionary *) dictionary |
1063 | { | 1108 | { |
1064 | NSMutableArray *parts = [[NSMutableArray alloc] init]; | 1109 | NSMutableArray *parts = [[NSMutableArray alloc] init]; |
1065 | for (id key in dictionary) | 1110 | for (id key in dictionary) |
1066 | { | 1111 | { |
1067 | NSString *encodedValue = [[dictionary[key] description] urlencode]; | 1112 | NSString *encodedValue = [[dictionary[key] description] urlencode]; |
1068 | NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; | 1113 | NSString *encodedKey = [[key description] urlencode];//[[key description] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; |
1069 | NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; | 1114 | NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; |
1070 | [parts addObject:part]; | 1115 | [parts addObject:part]; |
1071 | } | 1116 | } |
1072 | NSString *encodedDictionary = [parts componentsJoinedByString:@"&"]; | 1117 | NSString *encodedDictionary = [parts componentsJoinedByString:@"&"]; |
1073 | return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; | 1118 | return [encodedDictionary dataUsingEncoding: NSUTF8StringEncoding]; |
1074 | } | 1119 | } |
1075 | 1120 | ||
1076 | - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion | 1121 | - (NSURLSessionDataTask *) _request:(NSString *)address method:(NSString *)method token:(NSString *) token paras:(NSDictionary *)paras completion:(void (^)(NSData *data, NSError *error))completion |
1077 | { | 1122 | { |
1078 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; | 1123 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:address]]; |
1079 | request.HTTPMethod = method; | 1124 | request.HTTPMethod = method; |
1080 | [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; | 1125 | [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; |
1081 | [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; | 1126 | [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; |
1082 | if(token != nil && ![token isEqual: @""]) { | 1127 | if(token != nil && ![token isEqual: @""]) { |
1083 | [request setValue: token forHTTPHeaderField: @"token"]; | 1128 | [request setValue: token forHTTPHeaderField: @"token"]; |
1084 | } | 1129 | } |
1085 | [request setTimeoutInterval:self.timeOutInterval]; | 1130 | [request setTimeoutInterval:self.timeOutInterval]; |
1086 | 1131 | ||
1087 | if (paras != nil) | 1132 | if (paras != nil) |
1088 | { | 1133 | { |
1089 | NSData *encodedData = [self _encodeDictionary: paras]; | 1134 | NSData *encodedData = [self _encodeDictionary: paras]; |
1090 | [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"]; | 1135 | [request setValue: [NSString stringWithFormat: @"%lu", (unsigned long) encodedData.length] forHTTPHeaderField: @"Content-Length"]; |
1091 | [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"]; | 1136 | [request setValue: @"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField: @"Content-Type"]; |
1092 | [request setHTTPBody: encodedData]; | 1137 | [request setHTTPBody: encodedData]; |
1093 | } | 1138 | } |
1094 | 1139 | ||
1095 | //NSURLSession *session = [NSURLSession sharedSession]; | 1140 | //NSURLSession *session = [NSURLSession sharedSession]; |
1096 | NSURLSessionConfiguration *defaultConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; | 1141 | NSURLSessionConfiguration *defaultConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; |
1097 | [defaultConfiguration setHTTPMaximumConnectionsPerHost:20]; | 1142 | [defaultConfiguration setHTTPMaximumConnectionsPerHost:20]; |
1098 | NSOperationQueue *operationQueue = [NSOperationQueue mainQueue]; | 1143 | NSOperationQueue *operationQueue = [NSOperationQueue mainQueue]; |
1099 | operationQueue.maxConcurrentOperationCount = 20; | 1144 | operationQueue.maxConcurrentOperationCount = 20; |
1100 | NSURLSession *session = [NSURLSession sessionWithConfiguration:defaultConfiguration delegate:nil delegateQueue:operationQueue]; | 1145 | NSURLSession *session = [NSURLSession sessionWithConfiguration:defaultConfiguration delegate:nil delegateQueue:operationQueue]; |
1101 | NSURLSessionDataTask *task = [session dataTaskWithRequest:request | 1146 | NSURLSessionDataTask *task = [session dataTaskWithRequest:request |
1102 | completionHandler: | 1147 | completionHandler: |
1103 | ^(NSData *data, NSURLResponse *response, NSError *error) { | 1148 | ^(NSData *data, NSURLResponse *response, NSError *error) { |
1104 | if (completion == NULL) { | 1149 | if (completion == NULL) { |
1105 | return ; | 1150 | return ; |
1106 | } | 1151 | } |
1107 | if (error == nil) | 1152 | if (error == nil) |
1108 | { | 1153 | { |
1109 | completion(data, nil); | 1154 | completion(data, nil); |
1110 | } | 1155 | } |
1111 | else | 1156 | else |
1112 | { | 1157 | { |
1113 | completion(nil, error); | 1158 | completion(nil, error); |
1114 | } | 1159 | } |
1115 | }]; | 1160 | }]; |
1116 | [task resume]; | 1161 | [task resume]; |
1117 | return task; | 1162 | return task; |
1118 | } | 1163 | } |
1119 | 1164 | ||
1120 | -(void)waitUntilDone:(void(^)(void))waitBlock { | 1165 | -(void)waitUntilDone:(void(^)(void))waitBlock { |
1121 | //use your statement or call method here | 1166 | //use your statement or call method here |
1122 | if(waitBlock){ | 1167 | if(waitBlock){ |
1123 | waitBlock(); | 1168 | waitBlock(); |
1124 | } | 1169 | } |
1125 | } | 1170 | } |
1126 | 1171 | ||
1127 | @end | 1172 | @end |
1128 | 1173 |