Manos Chorianopoulos

add steps service

...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>1</integer> 10 + <integer>0</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -1045,6 +1045,7 @@ ...@@ -1045,6 +1045,7 @@
1045 DYLIB_INSTALL_NAME_BASE = "@rpath"; 1045 DYLIB_INSTALL_NAME_BASE = "@rpath";
1046 GENERATE_INFOPLIST_FILE = YES; 1046 GENERATE_INFOPLIST_FILE = YES;
1047 INFOPLIST_KEY_NSHumanReadableCopyright = ""; 1047 INFOPLIST_KEY_NSHumanReadableCopyright = "";
1048 + INFOPLIST_KEY_NSMotionUsageDescription = "We are using motion usage in order to track your step count.";
1048 INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 1049 INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
1049 IPHONEOS_DEPLOYMENT_TARGET = 11.0; 1050 IPHONEOS_DEPLOYMENT_TARGET = 11.0;
1050 LD_RUNPATH_SEARCH_PATHS = ( 1051 LD_RUNPATH_SEARCH_PATHS = (
...@@ -1081,6 +1082,7 @@ ...@@ -1081,6 +1082,7 @@
1081 DYLIB_INSTALL_NAME_BASE = "@rpath"; 1082 DYLIB_INSTALL_NAME_BASE = "@rpath";
1082 GENERATE_INFOPLIST_FILE = YES; 1083 GENERATE_INFOPLIST_FILE = YES;
1083 INFOPLIST_KEY_NSHumanReadableCopyright = ""; 1084 INFOPLIST_KEY_NSHumanReadableCopyright = "";
1085 + INFOPLIST_KEY_NSMotionUsageDescription = "We are using motion usage in order to track your step count.";
1084 INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 1086 INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
1085 IPHONEOS_DEPLOYMENT_TARGET = 11.0; 1087 IPHONEOS_DEPLOYMENT_TARGET = 11.0;
1086 LD_RUNPATH_SEARCH_PATHS = ( 1088 LD_RUNPATH_SEARCH_PATHS = (
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>0</integer> 10 + <integer>1</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -35,6 +35,16 @@ import SwiftEventBus ...@@ -35,6 +35,16 @@ import SwiftEventBus
35 webview.configuration.userContentController.add(self, name: "Cosmote") 35 webview.configuration.userContentController.add(self, name: "Cosmote")
36 } 36 }
37 37
38 + // MARK: - API Calls
39 + func startTrackingSteps() {
40 + swiftApi().startTrackingSteps(startTrackingStepsCallback)
41 + }
42 +
43 + func startTrackingStepsCallback (_ steps: Int) -> Void {
44 + DispatchQueue.main.async {
45 + }
46 + }
47 +
38 // MARK: - WKNavigationDelegate 48 // MARK: - WKNavigationDelegate
39 func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { 49 func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
40 50
...@@ -129,11 +139,13 @@ import SwiftEventBus ...@@ -129,11 +139,13 @@ import SwiftEventBus
129 let pacingEvent = swiftApi.WarplyPacingEventModel() 139 let pacingEvent = swiftApi.WarplyPacingEventModel()
130 pacingEvent._isVisible = true 140 pacingEvent._isVisible = true
131 SwiftEventBus.post("pacing", sender: pacingEvent) 141 SwiftEventBus.post("pacing", sender: pacingEvent)
142 + self.startTrackingSteps()
132 143
133 } else if (eventArray[1] == "steps" && eventArray[2] == "shortcutDisabled") { 144 } else if (eventArray[1] == "steps" && eventArray[2] == "shortcutDisabled") {
134 let pacingEvent = swiftApi.WarplyPacingEventModel() 145 let pacingEvent = swiftApi.WarplyPacingEventModel()
135 pacingEvent._isVisible = false 146 pacingEvent._isVisible = false
136 SwiftEventBus.post("pacing", sender: pacingEvent) 147 SwiftEventBus.post("pacing", sender: pacingEvent)
148 + swiftApi().stopTrackingSteps()
137 149
138 } else if (eventArray[1] == "request" || eventArray[1] == "response") { 150 } else if (eventArray[1] == "request" || eventArray[1] == "response") {
139 print("**************** WARPLY Webview Log START *****************") 151 print("**************** WARPLY Webview Log START *****************")
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
20 - (void) setToStage; 20 - (void) setToStage;
21 - (void) setLang:(NSString*) lang; 21 - (void) setLang:(NSString*) lang;
22 - (void) getSteps:(void(^)(CMPedometerData* stepsData)) completion; 22 - (void) getSteps:(void(^)(CMPedometerData* stepsData)) completion;
23 +- (void) startTrackingSteps:(void(^)(NSNumber * _Nullable numberOfSteps))callback;
24 +- (void) stopTrackingSteps;
23 // - (UIViewController *) openCoupons:(UIView*) parentView; 25 // - (UIViewController *) openCoupons:(UIView*) parentView;
24 //- (UIViewController *) openCoupon:(UIView*) parentView coupon:(NSDictionary*) coupon; 26 //- (UIViewController *) openCoupon:(UIView*) parentView coupon:(NSDictionary*) coupon;
25 //- (UIViewController *) openCouponBarcode:(UIView*) parentView coupon:(NSDictionary*) coupon; 27 //- (UIViewController *) openCouponBarcode:(UIView*) parentView coupon:(NSDictionary*) coupon;
...@@ -85,6 +87,7 @@ ...@@ -85,6 +87,7 @@
85 - (void)consumerIntegrationAsync:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 87 - (void)consumerIntegrationAsync:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
86 - (void)redeemCouponSetAsync:(NSString*)uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 88 - (void)redeemCouponSetAsync:(NSString*)uuid :(NSString*)communication_uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
87 - (void)getPacingDetailsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 89 - (void)getPacingDetailsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
90 +- (void)setPacingDetailsAsync:(NSNumber*)steps :(NSString*)date :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
88 - (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 91 - (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
89 - (void)cosmoteRetrieveSharingAsync:(NSString*)sharingId :(NSNumber*)accept :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 92 - (void)cosmoteRetrieveSharingAsync:(NSString*)sharingId :(NSNumber*)accept :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
90 - (void)getCosmoteUserAsync:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 93 - (void)getCosmoteUserAsync:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -18,8 +18,9 @@ NSString *WARP_HOST = @"engage.warp.ly"; ...@@ -18,8 +18,9 @@ NSString *WARP_HOST = @"engage.warp.ly";
18 NSString *WARP_ERROR_DOMAIN = @"engage.warp.ly"; 18 NSString *WARP_ERROR_DOMAIN = @"engage.warp.ly";
19 NSString *MERCHANT_ID; 19 NSString *MERCHANT_ID;
20 NSString *LANG; 20 NSString *LANG;
21 -NSDate *date; 21 +// NSDate *date;
22 -CMPedometer *pedometer; 22 +// CMPedometer *pedometer;
23 +CMPedometer *_pedometer;
23 NSString *VERIFY_URL = @"/partners/cosmote/verify"; 24 NSString *VERIFY_URL = @"/partners/cosmote/verify";
24 25
25 - (void)initialize:(NSDictionary *)launchOptions uuid:(NSString*)uuid merchantId:(NSString*)merchantId lang:(NSString*)lang{ 26 - (void)initialize:(NSDictionary *)launchOptions uuid:(NSString*)uuid merchantId:(NSString*)merchantId lang:(NSString*)lang{
...@@ -82,38 +83,68 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; ...@@ -82,38 +83,68 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
82 // } 83 // }
83 } 84 }
84 85
85 -- (void)queryDataFrom:(NSDate *)startDate toDate:(NSDate *)endDate { 86 +// - (void)queryDataFrom:(NSDate *)startDate toDate:(NSDate *)endDate {
86 - [pedometer queryPedometerDataFromDate:startDate 87 +// [pedometer queryPedometerDataFromDate:startDate
87 - toDate:endDate 88 +// toDate:endDate
88 - withHandler: 89 +// withHandler:
89 - ^(CMPedometerData *pedometerData, NSError *error) { 90 +// ^(CMPedometerData *pedometerData, NSError *error) {
90 91
91 - NSLog(@"data:%@, error:%@", pedometerData, error); 92 +// NSLog(@"data:%@, error:%@", pedometerData, error);
92 93
93 - dispatch_async(dispatch_get_main_queue(), ^{ 94 +// dispatch_async(dispatch_get_main_queue(), ^{
94 - if (error) { 95 +// if (error) {
95 - NSLog(@"Error = %@",error.userInfo); 96 +// NSLog(@"Error = %@",error.userInfo);
96 - } else { 97 +// } else {
97 - } 98 +// }
98 - }); 99 +// });
99 - }]; 100 +// }];
100 -} 101 +// }
102 +
103 +// - (void)recursiveQuery {
104 +// NSDate *to = [NSDate date];
105 +// NSDate *from = [to dateByAddingTimeInterval:-(24. * 3600.)];
106 +// [self queryDataFrom:from toDate:to];
107 +// }
108 +
109 +// - (void) getSteps:(void(^)(CMPedometerData* stepsData)) completion {
110 +// [pedometer startPedometerUpdatesFromDate:date
111 +// withHandler:^(CMPedometerData *pedometerData, NSError *error) {
112 +// dispatch_async(dispatch_get_main_queue(), ^{
113 +// completion(pedometerData);
114 +// });
115 +// }];
116 +// }
101 117
102 -- (void)recursiveQuery { 118 +
103 - NSDate *to = [NSDate date]; 119 +- (CMPedometer *)pedometer {
104 - NSDate *from = [to dateByAddingTimeInterval:-(24. * 3600.)]; 120 +
105 - [self queryDataFrom:from toDate:to]; 121 + if (!_pedometer) {
122 + _pedometer = [[CMPedometer alloc]init];
123 + }
124 + return _pedometer;
106 } 125 }
107 126
108 -- (void) getSteps:(void(^)(CMPedometerData* stepsData)) completion { 127 +- (void)startTrackingSteps:(void(^)(NSNumber * _Nullable numberOfSteps))callback {
109 - [pedometer startPedometerUpdatesFromDate:date 128 +
110 - withHandler:^(CMPedometerData *pedometerData, NSError *error) { 129 + // start live tracking
111 - dispatch_async(dispatch_get_main_queue(), ^{ 130 + [self.pedometer startPedometerUpdatesFromDate:[NSDate date] withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) {
112 - completion(pedometerData); 131 +
113 - }); 132 + // this block is called for each live update
133 + if (pedometerData != nil) {
134 + callback(pedometerData.numberOfSteps);
135 + } else if (error) {
136 + NSLog(@"startTrackingSteps error: %@", error);
137 + }
114 }]; 138 }];
115 } 139 }
116 140
141 +- (void)stopTrackingSteps {
142 +
143 + // stop live tracking
144 + [self.pedometer stopPedometerUpdates];
145 +}
146 +
147 +
117 - (void) setToStage { 148 - (void) setToStage {
118 WARP_PRODUCTION_BASE_URL = @"https://engage-stage.warp.ly"; 149 WARP_PRODUCTION_BASE_URL = @"https://engage-stage.warp.ly";
119 WARP_HOST = @"engage-stage.warp.ly"; 150 WARP_HOST = @"engage-stage.warp.ly";
...@@ -1421,6 +1452,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; ...@@ -1421,6 +1452,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
1421 }]; 1452 }];
1422 } 1453 }
1423 1454
1455 +- (void)setPacingDetailsAsync:(NSNumber*)steps :(NSString*)date :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1456 +{
1457 + [[Warply sharedService] setPacingDetailsWithSuccessBlock:steps :date :^(NSDictionary *response) {
1458 + if (success) {
1459 + success(response);
1460 + }
1461 + } failureBlock:^(NSError *error) {
1462 + failure(error);
1463 + }];
1464 +}
1465 +
1424 - (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure 1466 - (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1425 { 1467 {
1426 [[Warply sharedService] cosmoteSharingWithSuccessBlock:sharingId :^(NSDictionary *response) { 1468 [[Warply sharedService] cosmoteSharingWithSuccessBlock:sharingId :^(NSDictionary *response) {
......
...@@ -338,6 +338,8 @@ WL_VERSION_INTERFACE() ...@@ -338,6 +338,8 @@ WL_VERSION_INTERFACE()
338 338
339 - (void)getPacingDetailsWithSuccessBlock :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 339 - (void)getPacingDetailsWithSuccessBlock :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
340 340
341 +- (void)setPacingDetailsWithSuccessBlock:(NSNumber*)steps :(NSString*)date :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
342 +
341 - (void)editProfileWithSuccessBlock:(NSString*)firstName andLastName:(NSString*)lastName andEmail:(NSString*)email andSalutation:(NSString*)salutation andMsisdn:(NSString*)msisdn 343 - (void)editProfileWithSuccessBlock:(NSString*)firstName andLastName:(NSString*)lastName andEmail:(NSString*)email andSalutation:(NSString*)salutation andMsisdn:(NSString*)msisdn
342 andNickname:(NSString*)nickname andGender:(NSString*)gender andBirthday:(NSString*)birthday andNameDay:(NSString*)nameday andTaxID:(NSString*)taxID andProfileMetadata:(NSDictionary*)profileMetadata optin:(NSNumber*) optin newsLetter:(NSNumber*)newsletter 344 andNickname:(NSString*)nickname andGender:(NSString*)gender andBirthday:(NSString*)birthday andNameDay:(NSString*)nameday andTaxID:(NSString*)taxID andProfileMetadata:(NSDictionary*)profileMetadata optin:(NSNumber*) optin newsLetter:(NSNumber*)newsletter
343 andSMS:(NSNumber*)sms andSegmentation:(NSNumber*)segmentation andSMSSegmentation:(NSNumber*)smsSegmentation :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 345 andSMS:(NSNumber*)sms andSegmentation:(NSNumber*)segmentation andSMSSegmentation:(NSNumber*)smsSegmentation :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -1231,6 +1231,47 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -1231,6 +1231,47 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
1231 }]; 1231 }];
1232 } 1232 }
1233 1233
1234 +- (void)setPacingDetailsWithSuccessBlock:(NSNumber*)steps :(NSString*)date :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1235 +{
1236 + NSDictionary *postDictionary = @{@"consumer_data":@{@"method": @"steps", @"action": @"integration", @"operation": @"add", @"data":@{@"event": @"steps", @"type": @"counter", @"counter": steps, @"date": date}}};
1237 + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL];
1238 + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
1239 + if (success) {
1240 + success(contextResponse);
1241 + }
1242 + NSLog(@"**************** WARPLY Response *****************" );
1243 + NSLog(@"%@", contextResponse );
1244 + } failureBlock:^(NSError *error) {
1245 + if (failure) {
1246 + NSDictionary* dict = [NSDictionary alloc];
1247 + dict = [error userInfo];
1248 + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
1249 + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
1250 + [self refreshToken:^(NSDictionary *response) {
1251 + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
1252 + if (success) {
1253 + success(contextResponse);
1254 + }
1255 + NSLog(@"**************** WARPLY Response *****************" );
1256 + NSLog(@"%@", contextResponse );
1257 + } failureBlock:^(NSError *error) {
1258 + if (failure) {
1259 + failure(error);
1260 + }
1261 + }];
1262 + } failureBlock:^(NSError *error) {
1263 + if (failure) {
1264 + [_db executeUpdate:@"DROP TABLE requestVariables"];
1265 + failure(error);
1266 + }
1267 + NSLog(@"Error at token %@", error );
1268 + }];
1269 + }
1270 + NSLog(@"Error at set pacing details %@", error );
1271 + }
1272 + }];
1273 +}
1274 +
1234 - (void)consumerIntegrationWithSuccessBlock:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure 1275 - (void)consumerIntegrationWithSuccessBlock:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1235 { 1276 {
1236 NSMutableDictionary* data = [[NSMutableDictionary alloc] init]; 1277 NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
......
...@@ -22,8 +22,11 @@ public struct GlobalVariables { ...@@ -22,8 +22,11 @@ public struct GlobalVariables {
22 static var ccmsCampaigns: Array<swiftApi.LoyaltyContextualOfferModel> = [] 22 static var ccmsCampaigns: Array<swiftApi.LoyaltyContextualOfferModel> = []
23 static var dealsSum: Float = 0.0 23 static var dealsSum: Float = 0.0
24 static var seasonalList: Array<swiftApi.LoyaltyGiftsForYouPackage> = [] 24 static var seasonalList: Array<swiftApi.LoyaltyGiftsForYouPackage> = []
25 + static var savedSteps: Int = 0
25 } 26 }
26 27
28 +var timer: DispatchSourceTimer?
29 +
27 public class swiftApi { 30 public class swiftApi {
28 31
29 public init() { 32 public init() {
...@@ -37,7 +40,103 @@ public class swiftApi { ...@@ -37,7 +40,103 @@ public class swiftApi {
37 public func setUserTag(_ newUserTag: String) -> Void { 40 public func setUserTag(_ newUserTag: String) -> Void {
38 UserDefaults.standard.set(newUserTag, forKey: "userTag") 41 UserDefaults.standard.set(newUserTag, forKey: "userTag")
39 } 42 }
43 +
44 + public func getSteps() -> Int {
45 + return UserDefaults.standard.integer(forKey: "steps")
46 + }
47 +
48 + public func setSteps(_ newValue: Int) -> Void {
49 + UserDefaults.standard.set(newValue, forKey: "steps")
50 + }
51 +
52 +
53 + public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
54 + let instanceOfMyApi = MyApi()
55 + instanceOfMyApi.startTrackingSteps(startTrackingCallback)
56 +
57 + swiftApi().startTimer()
58 +
59 +
60 + func startTrackingCallback(_ steps: NSNumber?) -> Void {
61 +
62 + if (steps != nil) {
63 + swiftApi().setSteps((steps as! Int) - GlobalVariables.savedSteps)
64 + }
65 +
66 + getStepsCallback(steps as? Int ?? 0)
67 + }
68 +
69 + }
40 70
71 + public func stopTrackingSteps() -> Void {
72 + let instanceOfMyApi = MyApi()
73 + instanceOfMyApi.stopTrackingSteps()
74 +
75 + stopTimer()
76 +
77 + let persistedSteps = swiftApi().getSteps()
78 + if (persistedSteps > 0) {
79 +
80 + let currentDateTime = Date()
81 + let dateFormatter = DateFormatter()
82 + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
83 + let dateString = dateFormatter.string(from: currentDateTime)
84 +
85 + swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback)
86 + }
87 +
88 + func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void {
89 + if (responseData != nil) {
90 + DispatchQueue.main.async {
91 + if (responseData?.getStatus == 1) {
92 + }
93 + }
94 + } else {
95 + }
96 + }
97 + }
98 +
99 + func startTimer() {
100 + let queue = DispatchQueue(label: Bundle.main.bundleIdentifier! + ".timer")
101 + timer = DispatchSource.makeTimerSource(queue: queue)
102 + timer!.schedule(deadline: .now(), repeating: .seconds(10))
103 + timer!.setEventHandler { [weak self] in
104 + // do whatever stuff you want on the background queue here here
105 +
106 + let persistedSteps = swiftApi().getSteps()
107 + if (persistedSteps > 0) {
108 +
109 + let currentDateTime = Date()
110 + let dateFormatter = DateFormatter()
111 + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
112 + let dateString = dateFormatter.string(from: currentDateTime)
113 +
114 + swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback)
115 + }
116 +
117 + DispatchQueue.main.async {
118 + // update your model objects and/or UI here
119 + }
120 + }
121 + timer!.resume()
122 +
123 + func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void {
124 + if (responseData != nil) {
125 + DispatchQueue.main.async {
126 + if (responseData?.getStatus == 1) {
127 + }
128 + }
129 + } else {
130 + }
131 + }
132 + }
133 +
134 + func stopTimer() {
135 + timer?.cancel()
136 + timer = nil
137 + }
138 +
139 +
41 public class DFY { 140 public class DFY {
42 let couponCode: String? 141 let couponCode: String?
43 let merchantId: String? 142 let merchantId: String?
...@@ -3442,6 +3541,44 @@ public class swiftApi { ...@@ -3442,6 +3541,44 @@ public class swiftApi {
3442 } 3541 }
3443 3542
3444 3543
3544 + public func setPacingDetailsAsync(_ steps: Int, _ date: String, _ setPacingDetailsCallback: @escaping (_ responseData: GenericResponseModel?) -> Void) -> Void {
3545 +
3546 + let instanceOfMyApi = MyApi()
3547 + instanceOfMyApi.setPacingDetailsAsync(steps as NSNumber, date, pacingCallback, failureBlock: pacingFailureCallback)
3548 +
3549 + func pacingCallback(_ responseData: [AnyHashable: Any]?) -> Void {
3550 +
3551 +
3552 + if let responseDataDictionary = responseData as? [String: AnyObject] {
3553 + if (responseDataDictionary["status"] as? Int == 1) {
3554 + GlobalVariables.savedSteps += swiftApi().getSteps()
3555 + swiftApi().setSteps(0)
3556 +
3557 + if let responseDataDictionary = responseData as? [String: Any] {
3558 +
3559 + let tempResponse = GenericResponseModel(dictionary: responseDataDictionary)
3560 + setPacingDetailsCallback(tempResponse);
3561 +
3562 + } else {
3563 + setPacingDetailsCallback(nil)
3564 + }
3565 +
3566 + } else {
3567 + setPacingDetailsCallback(nil)
3568 + }
3569 +
3570 + } else {
3571 + setPacingDetailsCallback(nil)
3572 + }
3573 + }
3574 +
3575 + func pacingFailureCallback(_ error: Error?) -> Void {
3576 + print("setPacingDetails error: ")
3577 + setPacingDetailsCallback(nil)
3578 + }
3579 + }
3580 +
3581 +
3445 public class SharingResponseModel { 3582 public class SharingResponseModel {
3446 private var modal_text: String 3583 private var modal_text: String
3447 private var status: String 3584 private var status: String
......