Showing
1 changed file
with
24 additions
and
1 deletions
... | @@ -51,6 +51,29 @@ public class swiftApi { | ... | @@ -51,6 +51,29 @@ public class swiftApi { |
51 | 51 | ||
52 | 52 | ||
53 | public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { | 53 | public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { |
54 | + | ||
55 | + // Check if there are persistedSteps from previous app kill and save them | ||
56 | + let persistedSteps = swiftApi().getSteps() | ||
57 | + if (persistedSteps > 0) { | ||
58 | + | ||
59 | + let currentDateTime = Date() | ||
60 | + let dateFormatter = DateFormatter() | ||
61 | + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | ||
62 | + let dateString = dateFormatter.string(from: currentDateTime) | ||
63 | + | ||
64 | + swiftApi().setPacingDetailsAsync(persistedSteps, dateString, setPacingDetailsAsyncCallback) | ||
65 | + } | ||
66 | + | ||
67 | + func setPacingDetailsAsyncCallback (_ responseData: swiftApi.GenericResponseModel?) -> Void { | ||
68 | + if (responseData != nil) { | ||
69 | + DispatchQueue.main.async { | ||
70 | + if (responseData?.getStatus == 1) { | ||
71 | + } | ||
72 | + } | ||
73 | + } else { | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
54 | let instanceOfMyApi = MyApi() | 77 | let instanceOfMyApi = MyApi() |
55 | instanceOfMyApi.startTrackingSteps(startTrackingCallback) | 78 | instanceOfMyApi.startTrackingSteps(startTrackingCallback) |
56 | 79 | ||
... | @@ -107,7 +130,7 @@ public class swiftApi { | ... | @@ -107,7 +130,7 @@ public class swiftApi { |
107 | 130 | ||
108 | let queue = DispatchQueue(label: Bundle.main.bundleIdentifier! + ".timer") | 131 | let queue = DispatchQueue(label: Bundle.main.bundleIdentifier! + ".timer") |
109 | timer = DispatchSource.makeTimerSource(queue: queue) | 132 | timer = DispatchSource.makeTimerSource(queue: queue) |
110 | - timer!.schedule(deadline: .now(), repeating: .seconds(10)) | 133 | + timer!.schedule(deadline: .now(), repeating: .seconds(60 * 15)) |
111 | timer!.setEventHandler { [weak self] in | 134 | timer!.setEventHandler { [weak self] in |
112 | // do whatever stuff you want on the background queue here here | 135 | // do whatever stuff you want on the background queue here here |
113 | print("========= interval! =========") | 136 | print("========= interval! =========") | ... | ... |
-
Please register or login to post a comment