Showing
2 changed files
with
150 additions
and
56 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) { |
702 | - FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | 703 | + @try { |
703 | - while ([accessTokenSet next]) { | 704 | + FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; |
704 | - accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | 705 | + while ([accessTokenSet next]) { |
706 | + accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | ||
707 | + } | ||
705 | } | 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,25 +1083,41 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1069,25 +1083,41 @@ 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 = @""; |
1075 | - while ([refreshTokenSet next]) { | ||
1076 | - refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; | ||
1077 | - } | ||
1078 | - FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | ||
1079 | -// NSString *clientId = [NSString alloc]; | ||
1080 | NSString *clientId = @""; | 1087 | NSString *clientId = @""; |
1081 | - while ([clientIdSet next]) { | ||
1082 | - clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; | ||
1083 | - } | ||
1084 | - FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | ||
1085 | -// NSString *clientSecret = [NSString alloc]; | ||
1086 | NSString *clientSecret = @""; | 1088 | NSString *clientSecret = @""; |
1087 | - while ([clientSecretSet next]) { | 1089 | + |
1088 | - clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; | 1090 | + @try { |
1091 | + FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | ||
1092 | + // NSString *refreshToken = @""; | ||
1093 | + while ([refreshTokenSet next]) { | ||
1094 | + refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; | ||
1095 | + } | ||
1096 | + FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | ||
1097 | + // NSString *clientId = [NSString alloc]; | ||
1098 | + // NSString *clientId = @""; | ||
1099 | + while ([clientIdSet next]) { | ||
1100 | + clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; | ||
1101 | + } | ||
1102 | + FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | ||
1103 | + // NSString *clientSecret = [NSString alloc]; | ||
1104 | + // NSString *clientSecret = @""; | ||
1105 | + while ([clientSecretSet next]) { | ||
1106 | + clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; | ||
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"); | ||
1089 | } | 1118 | } |
1090 | 1119 | ||
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]; |
1093 | [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { | 1123 | [self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) { |
... | @@ -1125,23 +1155,38 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1125,23 +1155,38 @@ 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 = @""; |
1131 | - while ([refreshTokenSet next]) { | ||
1132 | - refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; | ||
1133 | - } | ||
1134 | - FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | ||
1135 | -// NSString *clientId = [NSString alloc]; | ||
1136 | NSString *clientId = @""; | 1159 | NSString *clientId = @""; |
1137 | - while ([clientIdSet next]) { | ||
1138 | - clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; | ||
1139 | - } | ||
1140 | - FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | ||
1141 | -// NSString *clientSecret = [NSString alloc]; | ||
1142 | NSString *clientSecret = @""; | 1160 | NSString *clientSecret = @""; |
1143 | - while ([clientSecretSet next]) { | 1161 | + |
1144 | - clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; | 1162 | + @try { |
1163 | + FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | ||
1164 | + // NSString *refreshToken = @""; | ||
1165 | + while ([refreshTokenSet next]) { | ||
1166 | + refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; | ||
1167 | + } | ||
1168 | + FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | ||
1169 | + // NSString *clientId = [NSString alloc]; | ||
1170 | + // NSString *clientId = @""; | ||
1171 | + while ([clientIdSet next]) { | ||
1172 | + clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; | ||
1173 | + } | ||
1174 | + FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | ||
1175 | + // NSString *clientSecret = [NSString alloc]; | ||
1176 | + // NSString *clientSecret = @""; | ||
1177 | + while ([clientSecretSet next]) { | ||
1178 | + clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; | ||
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"); | ||
1145 | } | 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", }; |
... | @@ -1181,23 +1226,38 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1181,23 +1226,38 @@ 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 = @""; |
1187 | - while ([refreshTokenSet next]) { | ||
1188 | - refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; | ||
1189 | - } | ||
1190 | - FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | ||
1191 | -// NSString *clientId = [NSString alloc]; | ||
1192 | NSString *clientId = @""; | 1230 | NSString *clientId = @""; |
1193 | - while ([clientIdSet next]) { | ||
1194 | - clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; | ||
1195 | - } | ||
1196 | - FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | ||
1197 | -// NSString *clientSecret = [NSString alloc]; | ||
1198 | NSString *clientSecret = @""; | 1231 | NSString *clientSecret = @""; |
1199 | - while ([clientSecretSet next]) { | 1232 | + |
1200 | - clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; | 1233 | + @try { |
1234 | + FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"]; | ||
1235 | + // NSString *refreshToken = @""; | ||
1236 | + while ([refreshTokenSet next]) { | ||
1237 | + refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue]; | ||
1238 | + } | ||
1239 | + FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"]; | ||
1240 | + // NSString *clientId = [NSString alloc]; | ||
1241 | + // NSString *clientId = @""; | ||
1242 | + while ([clientIdSet next]) { | ||
1243 | + clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue]; | ||
1244 | + } | ||
1245 | + FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"]; | ||
1246 | + // NSString *clientSecret = [NSString alloc]; | ||
1247 | + // NSString *clientSecret = @""; | ||
1248 | + while ([clientSecretSet next]) { | ||
1249 | + clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue]; | ||
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"); | ||
1201 | } | 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", }; |
... | @@ -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) { |
4531 | - FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | 4592 | + // FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; |
4532 | - while ([accessTokenSet next]) { | 4593 | + // while ([accessTokenSet next]) { |
4533 | - accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | 4594 | + // accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; |
4534 | - } | 4595 | + // } |
4596 | + @try { | ||
4597 | + FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | ||
4598 | + while ([accessTokenSet next]) { | ||
4599 | + accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | ||
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) { |
4670 | - FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | 4748 | + @try { |
4671 | - while ([accessTokenSet next]) { | 4749 | + FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; |
4672 | - accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | 4750 | + while ([accessTokenSet next]) { |
4673 | - } | 4751 | + accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; |
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