Commit 256868a43c9dfabca8282ec75ee15b33e9df2c01
1 parent
b50303b97d
Exists in
master
and in
1 other branch
update page 1 to page 5 file lifelog.ppt
Showing 8 changed files with 106 additions and 4 deletions Side-by-side Diff
LifeLog/LifeLog/AppDelegate.m
| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | #import "RankingViewController.h" |
| 14 | 14 | #import "MapViewController.h" |
| 15 | 15 | #import "SNSViewController.h" |
| 16 | +#import "ServerAPI.h" | |
| 16 | 17 | |
| 17 | 18 | @interface AppDelegate () |
| 18 | 19 | |
| 19 | 20 | |
| ... | ... | @@ -28,14 +29,16 @@ |
| 28 | 29 | // Override point for customization after application launch. |
| 29 | 30 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
| 30 | 31 | |
| 31 | - if ([[NSUserDefaults standardUserDefaults] objectForKey:@"User_Login"]) { | |
| 32 | - [self gotoMainMenu]; | |
| 33 | - } | |
| 34 | - else { | |
| 32 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; | |
| 33 | + User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; | |
| 34 | + if (user == nil) { | |
| 35 | 35 | LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil]; |
| 36 | 36 | UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:loginVC]; |
| 37 | 37 | self.window.rootViewController = navigation; |
| 38 | 38 | [self.window makeKeyAndVisible]; |
| 39 | + } | |
| 40 | + else { | |
| 41 | + [self gotoMainMenu]; | |
| 39 | 42 | } |
| 40 | 43 | |
| 41 | 44 | return YES; |
LifeLog/LifeLog/HomeViewController.m
| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | #import "TodayViewController.h" |
| 14 | 14 | #import "Utilities.h" |
| 15 | 15 | #import <MBProgressHUD/MBProgressHUD.h> |
| 16 | +#import "ServerAPI.h" | |
| 16 | 17 | |
| 17 | 18 | static NSInteger numberTotal = 10000; |
| 18 | 19 | |
| ... | ... | @@ -59,6 +60,34 @@ |
| 59 | 60 | self.avatar.layer.borderColor = [[UIColor whiteColor] CGColor]; |
| 60 | 61 | self.avatar.layer.cornerRadius = self.avatar.frame.size.width/2.0f; |
| 61 | 62 | self.avatar.layer.masksToBounds = YES; |
| 63 | + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kUser]; | |
| 64 | + User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; | |
| 65 | + if (user != nil) { | |
| 66 | + NSString *linkImage = [NSString stringWithFormat:@"%@%@", kServerAddress, user.profile_image]; | |
| 67 | + NSURL *urlImage = [NSURL URLWithString:linkImage]; | |
| 68 | + NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; | |
| 69 | + sessionConfig.timeoutIntervalForRequest = 30.0; | |
| 70 | + sessionConfig.timeoutIntervalForResource = 60.0; | |
| 71 | + sessionConfig.HTTPMaximumConnectionsPerHost = 20; | |
| 72 | + sessionConfig.allowsCellularAccess = YES; | |
| 73 | + HomeViewController __weak *weakSelf = self; | |
| 74 | + NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig]; | |
| 75 | + NSURLSessionDataTask *downloadPhotoTask = [session | |
| 76 | + dataTaskWithURL:urlImage completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { | |
| 77 | + if (weakSelf == nil) | |
| 78 | + { | |
| 79 | + return; | |
| 80 | + } | |
| 81 | + if (error == nil) { | |
| 82 | + UIImage *image = [[UIImage alloc] initWithData:data]; | |
| 83 | + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ | |
| 84 | + weakSelf.avatar.image = image; | |
| 85 | + }]; | |
| 86 | + } | |
| 87 | + }]; | |
| 88 | + [downloadPhotoTask resume]; | |
| 89 | + } | |
| 90 | + | |
| 62 | 91 | self.lblNotice.text = NSLocalizedString(@"lifelog.home.notice", nil); |
| 63 | 92 | |
| 64 | 93 | _dateCurrent = [NSDate date]; |
LifeLog/LifeLog/LoginViewController.m
| ... | ... | @@ -59,6 +59,11 @@ |
| 59 | 59 | [[ServerAPI server] loginWithEmail:_tfEmail.text Password:_tfPassword.text CompletionHandler:^(User *user, NSString *token, NSError *error) { |
| 60 | 60 | if (error == nil) { |
| 61 | 61 | // save user and goto MainMenu |
| 62 | + // For Saving | |
| 63 | + NSData *dataSave = [NSKeyedArchiver archivedDataWithRootObject:user]; | |
| 64 | + [[NSUserDefaults standardUserDefaults] setObject:dataSave forKey:kUser]; | |
| 65 | + [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; | |
| 66 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 62 | 67 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 63 | 68 | [[AppDelegate sharedAppDelegate] gotoMainMenu]; |
| 64 | 69 | }); |
LifeLog/LifeLog/RegisterViewController.m
| ... | ... | @@ -534,6 +534,11 @@ |
| 534 | 534 | return ; |
| 535 | 535 | } |
| 536 | 536 | if (error == nil) { |
| 537 | + // For Saving | |
| 538 | + NSData *dataSave = [NSKeyedArchiver archivedDataWithRootObject:user]; | |
| 539 | + [[NSUserDefaults standardUserDefaults] setObject:dataSave forKey:kUser]; | |
| 540 | + [[NSUserDefaults standardUserDefaults] setObject:token forKey:kToken]; | |
| 541 | + [[NSUserDefaults standardUserDefaults] synchronize]; | |
| 537 | 542 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 538 | 543 | [[AppDelegate sharedAppDelegate] gotoMainMenu]; |
| 539 | 544 | }); |
LifeLog/LifeLog/ServerAPI.h
LifeLog/LifeLog/ServerAPI.m
| ... | ... | @@ -9,6 +9,8 @@ |
| 9 | 9 | #import "ServerAPI.h" |
| 10 | 10 | |
| 11 | 11 | NSString *const kServerAddress = @"http://clover.timesfun.jp:9001/"; |
| 12 | +NSString *const kUser = @"KEY_USER"; | |
| 13 | +NSString *const kToken = @"KEY_TOKEN"; | |
| 12 | 14 | |
| 13 | 15 | @implementation NSString (NSString_Extended) |
| 14 | 16 | - (NSString *)urlencode { |
| ... | ... | @@ -86,6 +88,17 @@ |
| 86 | 88 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; |
| 87 | 89 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; |
| 88 | 90 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; |
| 91 | + user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; | |
| 92 | + user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; | |
| 93 | + user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; | |
| 94 | + user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; | |
| 95 | + user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; | |
| 96 | + user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; | |
| 97 | + user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; | |
| 98 | + user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; | |
| 99 | + user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; | |
| 100 | + user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; | |
| 101 | + user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; | |
| 89 | 102 | completion(user, token, nil); |
| 90 | 103 | } |
| 91 | 104 | else { // status = 0 error |
| ... | ... | @@ -130,6 +143,17 @@ |
| 130 | 143 | user.height = [[NSString stringWithFormat:@"%@",dictUser[@"height"]] floatValue]; |
| 131 | 144 | user.weight = [[NSString stringWithFormat:@"%@",dictUser[@"weight"]] floatValue]; |
| 132 | 145 | user.user_description = [NSString stringWithFormat:@"%@",dictUser[@"description"]]; |
| 146 | + user.created_at = [NSString stringWithFormat:@"%@",dictUser[@"created_at"]]; | |
| 147 | + user.physical_activity = [NSString stringWithFormat:@"%@",dictUser[@"physical_activity"]]; | |
| 148 | + user.profile_image = [NSString stringWithFormat:@"%@",dictUser[@"profile_image"]]; | |
| 149 | + user.updated_at = [NSString stringWithFormat:@"%@",dictUser[@"updated_at"]]; | |
| 150 | + user.delete_flag = [[NSString stringWithFormat:@"%@",dictUser[@"delete_flag"]] intValue]; | |
| 151 | + user.fat_rate = [[NSString stringWithFormat:@"%@",dictUser[@"fat_rate"]] intValue]; | |
| 152 | + user.profiles_share = [[NSString stringWithFormat:@"%@",dictUser[@"profiles_share"]] intValue]; | |
| 153 | + user.remember_me = [[NSString stringWithFormat:@"%@",dictUser[@"remember_me"]] intValue]; | |
| 154 | + user.sound_notifications_share = [[NSString stringWithFormat:@"%@",dictUser[@"sound_notifications_share"]] intValue]; | |
| 155 | + user.spend_calo_in_day = [[NSString stringWithFormat:@"%@",dictUser[@"spend_calo_in_day"]] intValue]; | |
| 156 | + user.target = [[NSString stringWithFormat:@"%@",dictUser[@"target"]] intValue]; | |
| 133 | 157 | completion(user, token, nil); |
| 134 | 158 | } |
| 135 | 159 | else { // status = 0 error |
LifeLog/LifeLog/User.h
| ... | ... | @@ -22,5 +22,16 @@ |
| 22 | 22 | @property (nonatomic, strong) NSString *user_description; |
| 23 | 23 | @property (nonatomic, strong) NSString *email; |
| 24 | 24 | @property (nonatomic, strong) NSString *phone; |
| 25 | +@property (nonatomic, strong) NSString *created_at; | |
| 26 | +@property (nonatomic, assign) int delete_flag; | |
| 27 | +@property (nonatomic, assign) int fat_rate; | |
| 28 | +@property (nonatomic, strong) NSString *physical_activity; | |
| 29 | +@property (nonatomic, strong) NSString *profile_image; | |
| 30 | +@property (nonatomic, assign) int profiles_share; | |
| 31 | +@property (nonatomic, assign) int remember_me; | |
| 32 | +@property (nonatomic, assign) int sound_notifications_share; | |
| 33 | +@property (nonatomic, assign) int spend_calo_in_day; | |
| 34 | +@property (nonatomic, assign) int target; | |
| 35 | +@property (nonatomic, strong) NSString *updated_at; | |
| 25 | 36 | @end |
LifeLog/LifeLog/User.m
| ... | ... | @@ -28,6 +28,17 @@ |
| 28 | 28 | self.user_description = [decoder decodeObjectForKey:@"user_description"]; |
| 29 | 29 | self.email = [decoder decodeObjectForKey:@"email"]; |
| 30 | 30 | self.phone = [decoder decodeObjectForKey:@"phone"]; |
| 31 | + self.created_at = [decoder decodeObjectForKey:@"created_at"]; | |
| 32 | + self.physical_activity = [decoder decodeObjectForKey:@"physical_activity"]; | |
| 33 | + self.profile_image = [decoder decodeObjectForKey:@"profile_image"]; | |
| 34 | + self.updated_at = [decoder decodeObjectForKey:@"updated_at"]; | |
| 35 | + self.delete_flag = [decoder decodeIntForKey:@"delete_flag"]; | |
| 36 | + self.fat_rate = [decoder decodeIntForKey:@"fat_rate"]; | |
| 37 | + self.profiles_share = [decoder decodeIntForKey:@"profiles_share"]; | |
| 38 | + self.remember_me = [decoder decodeIntForKey:@"remember_me"]; | |
| 39 | + self.sound_notifications_share = [decoder decodeIntForKey:@"sound_notifications_share"]; | |
| 40 | + self.spend_calo_in_day = [decoder decodeIntForKey:@"spend_calo_in_day"]; | |
| 41 | + self.target = [decoder decodeIntForKey:@"target"]; | |
| 31 | 42 | |
| 32 | 43 | return self; |
| 33 | 44 | } |
| ... | ... | @@ -46,6 +57,17 @@ |
| 46 | 57 | [encoder encodeObject:self.user_description forKey:@"user_description"]; |
| 47 | 58 | [encoder encodeObject:self.email forKey:@"email"]; |
| 48 | 59 | [encoder encodeObject:self.phone forKey:@"phone"]; |
| 60 | + [encoder encodeObject:self.created_at forKey:@"created_at"]; | |
| 61 | + [encoder encodeObject:self.physical_activity forKey:@"physical_activity"]; | |
| 62 | + [encoder encodeObject:self.profile_image forKey:@"profile_image"]; | |
| 63 | + [encoder encodeObject:self.updated_at forKey:@"updated_at"]; | |
| 64 | + [encoder encodeInt:self.delete_flag forKey:@"delete_flag"]; | |
| 65 | + [encoder encodeInt:self.fat_rate forKey:@"fat_rate"]; | |
| 66 | + [encoder encodeInt:self.profiles_share forKey:@"profiles_share"]; | |
| 67 | + [encoder encodeInt:self.remember_me forKey:@"remember_me"]; | |
| 68 | + [encoder encodeInt:self.sound_notifications_share forKey:@"sound_notifications_share"]; | |
| 69 | + [encoder encodeInt:self.spend_calo_in_day forKey:@"spend_calo_in_day"]; | |
| 70 | + [encoder encodeInt:self.target forKey:@"target"]; | |
| 49 | 71 | } |
| 50 | 72 | @end |