Showing
2 changed files
with
115 additions
and
21 deletions
No preview for this file type
| ... | @@ -697,12 +697,26 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -697,12 +697,26 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
| 697 | [self createDBIfNeeded]; | 697 | [self createDBIfNeeded]; |
| 698 | [self initDBIfNeeded]; | 698 | [self initDBIfNeeded]; |
| 699 | [self restore]; | 699 | [self restore]; |
| 700 | - NSString *accessToken = [NSString alloc]; | 700 | +// NSString *accessToken = [NSString alloc]; |
| 701 | + NSString *accessToken = @""; | ||
| 701 | if ([_db tableExists:@"requestVariables"] == YES) { | 702 | if ([_db tableExists:@"requestVariables"] == YES) { |
| 703 | + @try { | ||
| 702 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | 704 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; |
| 703 | while ([accessTokenSet next]) { | 705 | while ([accessTokenSet next]) { |
| 704 | accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | 706 | accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; |
| 705 | } | 707 | } |
| 708 | + } | ||
| 709 | + @catch (NSException *exception) { | ||
| 710 | + NSLog(@"SELECT accessToken error: %@", exception.reason); | ||
| 711 | + } | ||
| 712 | + @finally { | ||
| 713 | +// NSLog(@"Finally condition"); | ||
| 714 | + } | ||
| 715 | + | ||
| 716 | + // FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | ||
| 717 | + // while ([accessTokenSet next]) { | ||
| 718 | + // accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | ||
| 719 | + // } | ||
| 706 | return accessToken; | 720 | return accessToken; |
| 707 | } | 721 | } |
| 708 | return @""; | 722 | return @""; |
| ... | @@ -1069,24 +1083,40 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1069,24 +1083,40 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
| 1069 | - (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1083 | - (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
| 1070 | { | 1084 | { |
| 1071 | if ([_db tableExists:@"requestVariables"] == YES) { | 1085 | if ([_db tableExists:@"requestVariables"] == YES) { |
| 1072 | - FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | ||
| 1073 | -// NSString *refreshToken = [NSString alloc]; | ||
| 1074 | NSString *refreshToken = @""; | 1086 | NSString *refreshToken = @""; |
| 1087 | + NSString *clientId = @""; | ||
| 1088 | + NSString *clientSecret = @""; | ||
| 1089 | + | ||
| 1090 | + @try { | ||
| 1091 | + FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | ||
| 1092 | + // NSString *refreshToken = @""; | ||
| 1075 | while ([refreshTokenSet next]) { | 1093 | while ([refreshTokenSet next]) { |
| 1076 | refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; | 1094 | refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; |
| 1077 | } | 1095 | } |
| 1078 | FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | 1096 | FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; |
| 1079 | -// NSString *clientId = [NSString alloc]; | 1097 | + // NSString *clientId = [NSString alloc]; |
| 1080 | - NSString *clientId = @""; | 1098 | + // NSString *clientId = @""; |
| 1081 | while ([clientIdSet next]) { | 1099 | while ([clientIdSet next]) { |
| 1082 | clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; | 1100 | clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; |
| 1083 | } | 1101 | } |
| 1084 | FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | 1102 | FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; |
| 1085 | -// NSString *clientSecret = [NSString alloc]; | 1103 | + // NSString *clientSecret = [NSString alloc]; |
| 1086 | - NSString *clientSecret = @""; | 1104 | + // NSString *clientSecret = @""; |
| 1087 | while ([clientSecretSet next]) { | 1105 | while ([clientSecretSet next]) { |
| 1088 | clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; | 1106 | clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; |
| 1089 | } | 1107 | } |
| 1108 | + } | ||
| 1109 | + @catch (NSException *exception) { | ||
| 1110 | + NSLog(@"SELECT Token error: %@", exception.reason); | ||
| 1111 | + if (failure) { | ||
| 1112 | + NSError *error = nil; | ||
| 1113 | + failure(error); | ||
| 1114 | + } | ||
| 1115 | + } | ||
| 1116 | + @finally { | ||
| 1117 | +// NSLog(@"Finally condition"); | ||
| 1118 | + } | ||
| 1119 | + | ||
| 1090 | 1120 | ||
| 1091 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; | 1121 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; |
| 1092 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; | 1122 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; |
| ... | @@ -1125,24 +1155,39 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1125,24 +1155,39 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
| 1125 | - (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1155 | - (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
| 1126 | { | 1156 | { |
| 1127 | if ([_db tableExists:@"requestVariables"] == YES) { | 1157 | if ([_db tableExists:@"requestVariables"] == YES) { |
| 1128 | - FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | ||
| 1129 | -// NSString *refreshToken = [NSString alloc]; | ||
| 1130 | NSString *refreshToken = @""; | 1158 | NSString *refreshToken = @""; |
| 1159 | + NSString *clientId = @""; | ||
| 1160 | + NSString *clientSecret = @""; | ||
| 1161 | + | ||
| 1162 | + @try { | ||
| 1163 | + FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | ||
| 1164 | + // NSString *refreshToken = @""; | ||
| 1131 | while ([refreshTokenSet next]) { | 1165 | while ([refreshTokenSet next]) { |
| 1132 | refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; | 1166 | refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; |
| 1133 | } | 1167 | } |
| 1134 | FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | 1168 | FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; |
| 1135 | -// NSString *clientId = [NSString alloc]; | 1169 | + // NSString *clientId = [NSString alloc]; |
| 1136 | - NSString *clientId = @""; | 1170 | + // NSString *clientId = @""; |
| 1137 | while ([clientIdSet next]) { | 1171 | while ([clientIdSet next]) { |
| 1138 | clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; | 1172 | clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; |
| 1139 | } | 1173 | } |
| 1140 | FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | 1174 | FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; |
| 1141 | -// NSString *clientSecret = [NSString alloc]; | 1175 | + // NSString *clientSecret = [NSString alloc]; |
| 1142 | - NSString *clientSecret = @""; | 1176 | + // NSString *clientSecret = @""; |
| 1143 | while ([clientSecretSet next]) { | 1177 | while ([clientSecretSet next]) { |
| 1144 | clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; | 1178 | clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; |
| 1145 | } | 1179 | } |
| 1180 | + } | ||
| 1181 | + @catch (NSException *exception) { | ||
| 1182 | + NSLog(@"SELECT Token error: %@", exception.reason); | ||
| 1183 | + if (failure) { | ||
| 1184 | + NSError *error = nil; | ||
| 1185 | + failure(error); | ||
| 1186 | + } | ||
| 1187 | + } | ||
| 1188 | + @finally { | ||
| 1189 | +// NSLog(@"Finally condition"); | ||
| 1190 | + } | ||
| 1146 | 1191 | ||
| 1147 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; | 1192 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; |
| 1148 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; | 1193 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; |
| ... | @@ -1181,24 +1226,39 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1181,24 +1226,39 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
| 1181 | - (void)refreshToken3rdTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1226 | - (void)refreshToken3rdTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
| 1182 | { | 1227 | { |
| 1183 | if ([_db tableExists:@"requestVariables"] == YES) { | 1228 | if ([_db tableExists:@"requestVariables"] == YES) { |
| 1184 | - FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | ||
| 1185 | -// NSString *refreshToken = [NSString alloc]; | ||
| 1186 | NSString *refreshToken = @""; | 1229 | NSString *refreshToken = @""; |
| 1230 | + NSString *clientId = @""; | ||
| 1231 | + NSString *clientSecret = @""; | ||
| 1232 | + | ||
| 1233 | + @try { | ||
| 1234 | + FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | ||
| 1235 | + // NSString *refreshToken = @""; | ||
| 1187 | while ([refreshTokenSet next]) { | 1236 | while ([refreshTokenSet next]) { |
| 1188 | refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; | 1237 | refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; |
| 1189 | } | 1238 | } |
| 1190 | FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | 1239 | FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; |
| 1191 | -// NSString *clientId = [NSString alloc]; | 1240 | + // NSString *clientId = [NSString alloc]; |
| 1192 | - NSString *clientId = @""; | 1241 | + // NSString *clientId = @""; |
| 1193 | while ([clientIdSet next]) { | 1242 | while ([clientIdSet next]) { |
| 1194 | clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; | 1243 | clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; |
| 1195 | } | 1244 | } |
| 1196 | FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | 1245 | FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; |
| 1197 | -// NSString *clientSecret = [NSString alloc]; | 1246 | + // NSString *clientSecret = [NSString alloc]; |
| 1198 | - NSString *clientSecret = @""; | 1247 | + // NSString *clientSecret = @""; |
| 1199 | while ([clientSecretSet next]) { | 1248 | while ([clientSecretSet next]) { |
| 1200 | clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; | 1249 | clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; |
| 1201 | } | 1250 | } |
| 1251 | + } | ||
| 1252 | + @catch (NSException *exception) { | ||
| 1253 | + NSLog(@"SELECT Token error: %@", exception.reason); | ||
| 1254 | + if (failure) { | ||
| 1255 | + NSError *error = nil; | ||
| 1256 | + failure(error); | ||
| 1257 | + } | ||
| 1258 | + } | ||
| 1259 | + @finally { | ||
| 1260 | +// NSLog(@"Finally condition"); | ||
| 1261 | + } | ||
| 1202 | 1262 | ||
| 1203 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; | 1263 | NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", }; |
| 1204 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; | 1264 | NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL]; |
| ... | @@ -4526,12 +4586,29 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) | ... | @@ -4526,12 +4586,29 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) |
| 4526 | 4586 | ||
| 4527 | //Set HTTP Headers | 4587 | //Set HTTP Headers |
| 4528 | time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; | 4588 | time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; |
| 4529 | - NSString *accessToken = [NSString alloc]; | 4589 | +// NSString *accessToken = [NSString alloc]; |
| 4590 | + NSString *accessToken = @""; | ||
| 4530 | if ([_db tableExists:@"requestVariables"] == YES) { | 4591 | if ([_db tableExists:@"requestVariables"] == YES) { |
| 4592 | + // FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | ||
| 4593 | + // while ([accessTokenSet next]) { | ||
| 4594 | + // accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | ||
| 4595 | + // } | ||
| 4596 | + @try { | ||
| 4531 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | 4597 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; |
| 4532 | while ([accessTokenSet next]) { | 4598 | while ([accessTokenSet next]) { |
| 4533 | accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | 4599 | accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; |
| 4534 | } | 4600 | } |
| 4601 | + } | ||
| 4602 | + @catch (NSException *exception) { | ||
| 4603 | + NSLog(@"SELECT accessToken error: %@", exception.reason); | ||
| 4604 | + if (failureBlock) { | ||
| 4605 | + NSError *error = nil; | ||
| 4606 | + failureBlock(error); | ||
| 4607 | + } | ||
| 4608 | + } | ||
| 4609 | + @finally { | ||
| 4610 | +// NSLog(@"Finally condition"); | ||
| 4611 | + } | ||
| 4535 | [_httpClient.requestSerializer setValue:[@"Bearer " stringByAppendingString:accessToken] forHTTPHeaderField:@"Authorization"]; | 4612 | [_httpClient.requestSerializer setValue:[@"Bearer " stringByAppendingString:accessToken] forHTTPHeaderField:@"Authorization"]; |
| 4536 | } | 4613 | } |
| 4537 | [_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"]; | 4614 | [_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"]; |
| ... | @@ -4665,12 +4742,29 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) | ... | @@ -4665,12 +4742,29 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) |
| 4665 | 4742 | ||
| 4666 | //Set HTTP Headers | 4743 | //Set HTTP Headers |
| 4667 | time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; | 4744 | time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; |
| 4668 | - NSString *accessToken = [NSString alloc]; | 4745 | +// NSString *accessToken = [NSString alloc]; |
| 4746 | + NSString *accessToken = @""; | ||
| 4669 | if ([_db tableExists:@"requestVariables"] == YES) { | 4747 | if ([_db tableExists:@"requestVariables"] == YES) { |
| 4748 | + @try { | ||
| 4670 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | 4749 | FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; |
| 4671 | while ([accessTokenSet next]) { | 4750 | while ([accessTokenSet next]) { |
| 4672 | accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | 4751 | accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; |
| 4673 | } | 4752 | } |
| 4753 | + } | ||
| 4754 | + @catch (NSException *exception) { | ||
| 4755 | + NSLog(@"SELECT accessToken error: %@", exception.reason); | ||
| 4756 | + if (failureBlock) { | ||
| 4757 | + NSError *error = nil; | ||
| 4758 | + failureBlock(error); | ||
| 4759 | + } | ||
| 4760 | + } | ||
| 4761 | + @finally { | ||
| 4762 | +// NSLog(@"Finally condition"); | ||
| 4763 | + } | ||
| 4764 | +// FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | ||
| 4765 | +// while ([accessTokenSet next]) { | ||
| 4766 | +// accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | ||
| 4767 | +// } | ||
| 4674 | [_httpClient.requestSerializer setValue:[@"Bearer " stringByAppendingString:accessToken] forHTTPHeaderField:@"Authorization"]; | 4768 | [_httpClient.requestSerializer setValue:[@"Bearer " stringByAppendingString:accessToken] forHTTPHeaderField:@"Authorization"]; |
| 4675 | } | 4769 | } |
| 4676 | [_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"]; | 4770 | [_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"]; | ... | ... |
-
Please register or login to post a comment