react-native-mytatva-rn-sdk 1.2.25 → 1.2.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -121,64 +121,58 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
121
121
|
try {
|
|
122
122
|
userToken = token
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
authenticateSDKService.getCGMData(
|
|
125
|
+
environment = if ("uat".uppercase() == "PROD") TATVA_ENVIRONMENT.PROD else TATVA_ENVIRONMENT.STAGE,
|
|
126
|
+
token = userToken,
|
|
127
|
+
responseListener = object : AuthenticateSDKService.ResponseListener {
|
|
128
|
+
override fun onResponseSuccess(response: String) {
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
token = userToken,
|
|
133
|
-
responseListener = object : AuthenticateSDKService.ResponseListener {
|
|
134
|
-
override fun onResponseSuccess(response: String) {
|
|
130
|
+
val response = Gson().fromJson(response, CgmSensorResponse::class.java)
|
|
131
|
+
val sensor = response.data?.firstOrNull()
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
val
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (isCurrentDateInRange(startDate, endDate)) {
|
|
148
|
-
|
|
149
|
-
println("Current date is in range")
|
|
150
|
-
|
|
151
|
-
val pocDevice =
|
|
152
|
-
RepositoryDevice.getInstance(BApplication.getContext()).latestDeviceIoThread
|
|
153
|
-
if (pocDevice != null) {
|
|
154
|
-
if (pocDevice.isUnBind) {
|
|
155
|
-
postEventDataToAPI(
|
|
156
|
-
pocDevice,
|
|
157
|
-
DeviceStatus.TRANSMITTER_DISCONNECT.id,
|
|
158
|
-
pocDevice.qrMessage
|
|
159
|
-
)
|
|
160
|
-
} else {
|
|
161
|
-
postEventDataToAPI(
|
|
162
|
-
pocDevice,
|
|
163
|
-
DeviceStatus.TRANSMITTER_DISCONNECT.id,
|
|
164
|
-
sensorId
|
|
165
|
-
)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
133
|
+
if (sensor != null && !sensor.startDate.isNullOrEmpty() && !sensor.endDate.isNullOrEmpty()) {
|
|
134
|
+
val startDate = sensor.startDate
|
|
135
|
+
val endDate = sensor.endDate
|
|
136
|
+
val sensorId = sensor.sensorId
|
|
137
|
+
|
|
138
|
+
println("Start Date: $startDate")
|
|
139
|
+
println("End Date: $endDate")
|
|
140
|
+
|
|
141
|
+
if (isCurrentDateInRange(startDate, endDate)) {
|
|
142
|
+
|
|
143
|
+
println("Current date is in range")
|
|
168
144
|
|
|
145
|
+
val pocDevice =
|
|
146
|
+
RepositoryDevice.getInstance(BApplication.getContext()).latestDeviceIoThread
|
|
147
|
+
if (pocDevice != null) {
|
|
148
|
+
if (pocDevice.isUnBind) {
|
|
149
|
+
postEventDataToAPI(
|
|
150
|
+
pocDevice,
|
|
151
|
+
DeviceStatus.TRANSMITTER_DISCONNECT.id,
|
|
152
|
+
pocDevice.qrMessage
|
|
153
|
+
)
|
|
154
|
+
}
|
|
169
155
|
} else {
|
|
170
|
-
|
|
156
|
+
postEventDataToAPI(
|
|
157
|
+
pocDevice,
|
|
158
|
+
DeviceStatus.TRANSMITTER_DISCONNECT.id,
|
|
159
|
+
sensorId
|
|
160
|
+
)
|
|
171
161
|
}
|
|
162
|
+
|
|
172
163
|
} else {
|
|
173
|
-
println("
|
|
164
|
+
println("Current date is out of range")
|
|
174
165
|
}
|
|
166
|
+
} else {
|
|
167
|
+
println("Start or End date not available")
|
|
175
168
|
}
|
|
169
|
+
}
|
|
176
170
|
|
|
177
|
-
|
|
178
|
-
}
|
|
171
|
+
override fun onResponseFail() {
|
|
179
172
|
}
|
|
180
|
-
|
|
181
|
-
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
|
|
182
176
|
} catch (e: Exception) {
|
|
183
177
|
Log.e("observeTransmitterUnbindStatus", "observeTransmitterUnbindStatus: ${e.message}")
|
|
184
178
|
}
|
package/ios/Support/API.swift
CHANGED
|
@@ -230,7 +230,7 @@ class API {
|
|
|
230
230
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
func getStatus(encryptionKey: String = PROD_ENC_KEY,
|
|
233
|
+
/*func getStatus(encryptionKey: String = PROD_ENC_KEY,
|
|
234
234
|
encryptionIv: String = PROD_ENC_IV) {
|
|
235
235
|
print("ios token:", TOKEN)
|
|
236
236
|
let url = URL(string: "https://api-feature2.mytatva.in/api/v8/cgm/status")!
|
|
@@ -289,7 +289,7 @@ class API {
|
|
|
289
289
|
}
|
|
290
290
|
task.resume()
|
|
291
291
|
|
|
292
|
-
}
|
|
292
|
+
}*/
|
|
293
293
|
|
|
294
294
|
// Example date range check function (assumes yyyy-MM-dd format)
|
|
295
295
|
func isCurrentDateInRange(startDate: String, endDate: String) -> Bool {
|
|
@@ -17,7 +17,7 @@ import Foundation
|
|
|
17
17
|
@objc public func callForObserveTransmitterUnbindStatus() {
|
|
18
18
|
let sensorID = UserDefaults.standard.string(forKey: "sensorId") ?? ""
|
|
19
19
|
if !sensorID.isEmpty {
|
|
20
|
-
|
|
20
|
+
viewModel.getStatus()
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -43,15 +43,16 @@ class FinalViewModel: NSObject {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
@objc public func initialize() {
|
|
46
|
-
|
|
46
|
+
//getStatus()
|
|
47
47
|
startCountDown()
|
|
48
48
|
|
|
49
49
|
if ((manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
|
|
50
50
|
manager.startScan()
|
|
51
|
+
debouncer.update(with: .disconnected)
|
|
51
52
|
} else {
|
|
52
53
|
print("here")
|
|
53
54
|
//debouncer.update(with: .connected)
|
|
54
|
-
//API.shared.sendStatus(status: .connected)
|
|
55
|
+
//API.shared.sendStatus(status: .connected) 计算 算法入参
|
|
55
56
|
if let last = manager.currentDevice { }
|
|
56
57
|
else {
|
|
57
58
|
//self.manager.closeBleSensor()
|
|
@@ -61,6 +62,93 @@ class FinalViewModel: NSObject {
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
}
|
|
65
|
+
func getStatus(encryptionKey: String = PROD_ENC_KEY,
|
|
66
|
+
encryptionIv: String = PROD_ENC_IV) {
|
|
67
|
+
print("ios token:", TOKEN)
|
|
68
|
+
let url = URL(string: "https://api-feature2.mytatva.in/api/v8/cgm/status")!
|
|
69
|
+
var request = URLRequest(url: url)
|
|
70
|
+
request.httpMethod = "GET"
|
|
71
|
+
|
|
72
|
+
// Set headers
|
|
73
|
+
//request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
74
|
+
request.addValue(PROD_API_KEY, forHTTPHeaderField: "api-key")
|
|
75
|
+
request.addValue(TOKEN, forHTTPHeaderField: "token")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// Set request body
|
|
79
|
+
|
|
80
|
+
// Perform request
|
|
81
|
+
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
|
82
|
+
if let error = error {
|
|
83
|
+
print("Error: \(error)")
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
guard let data = data else {
|
|
87
|
+
print("No data received")
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
if let responseString = String(data: data, encoding: .utf8) {
|
|
91
|
+
print("===>Server Response: \(responseString)")
|
|
92
|
+
if let decrypted = Crypto.shared.getDecryptedData(cipherText: responseString, encryptionKey: encryptionKey, encryptionIv: encryptionIv) {
|
|
93
|
+
print("===>Decrypted response (for verification): \(decrypted)")
|
|
94
|
+
|
|
95
|
+
if let decrptedData = decrypted.data(using: .utf8) {
|
|
96
|
+
let decoded = try? JSONDecoder().decode(CGMStatusResponse.self, from: decrptedData)
|
|
97
|
+
|
|
98
|
+
guard let sensor = decoded?.data.first,
|
|
99
|
+
!sensor.startDate.isEmpty,
|
|
100
|
+
!sensor.endDate.isEmpty else {
|
|
101
|
+
print("No valid sensor data")
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let startDateStr = sensor.startDate
|
|
106
|
+
let endDateStr = sensor.endDate
|
|
107
|
+
|
|
108
|
+
print("Start Date: \(startDateStr)")
|
|
109
|
+
print("End Date: \(endDateStr)")
|
|
110
|
+
UserDefaults.standard.set(sensor.sensorId, forKey: "sensorId")
|
|
111
|
+
if self.isCurrentDateInRange(startDate: startDateStr, endDate: endDateStr) {
|
|
112
|
+
print("Current date is in range")
|
|
113
|
+
if ((self.manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
|
|
114
|
+
self.manager.startScan()
|
|
115
|
+
self.debouncer.update(with: .disconnected)
|
|
116
|
+
} else {
|
|
117
|
+
print("here")
|
|
118
|
+
//debouncer.update(with: .connected)
|
|
119
|
+
//API.shared.sendStatus(status: .connected) 计算 算法入参
|
|
120
|
+
if let last = self.manager.currentDevice { }
|
|
121
|
+
else {
|
|
122
|
+
//self.manager.closeBleSensor()
|
|
123
|
+
//manager.startScan()
|
|
124
|
+
//self.debouncer.update(with: .disconnected)
|
|
125
|
+
//debouncer.update(with: .transmitterDisconnectBox)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// if KLTBluetoothManager.shared().currentDevice.initialEndDate != nil {
|
|
129
|
+
// self.sendStatus(status: .transmitterDisconnect)
|
|
130
|
+
// }
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
task.resume()
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
func isCurrentDateInRange(startDate: String, endDate: String) -> Bool {
|
|
141
|
+
let formatter = DateFormatter()
|
|
142
|
+
formatter.dateFormat = "yyyy-MM-dd"
|
|
143
|
+
guard let start = formatter.date(from: startDate),
|
|
144
|
+
let end = formatter.date(from: endDate) else {
|
|
145
|
+
return false
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let now = Date()
|
|
149
|
+
return (now >= start) && (now <= end)
|
|
150
|
+
}
|
|
151
|
+
|
|
64
152
|
func startCountDown() {
|
|
65
153
|
|
|
66
154
|
// Most recently connected device
|