From 928957744770d793862f8e379956ccf3609b9cd3 Mon Sep 17 00:00:00 2001 From: Guido Soranzio <7220550+gui-dos@users.noreply.github.com> Date: Fri, 12 Jul 2024 07:42:20 +0200 Subject: [PATCH 1/3] Workaround for compiling with Xcode 16 beta MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the beta of Xcode 16 compilation fails by reporting the error “The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions.” regarding the line https://github.com/JohanDegraeve/xdripswift/blob/fec1005899893ddf20e36675f3aad96547e8c99c/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreNFC.swift#L462 Simply replacing the final `+ (error?.localizedDescription ?? "none”)` with `+ error.debugDescription` makes xDrip compilable again. --- xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreNFC.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreNFC.swift b/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreNFC.swift index 9366212a3..d4a635781 100644 --- a/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreNFC.swift +++ b/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreNFC.swift @@ -459,7 +459,7 @@ class LibreNFC: NSObject, NFCTagReaderSessionDelegate { tag.customCommand(requestFlags: .highDataRate, customCommandCode: Int(cmd.code), customRequestParameters: cmd.parameters) { response, error in - let debugInfo = "NFC: '" + subCmd.description + " command response " + response.count.description + " bytes : 0x" + response.toHexString() + ", error: " + (error?.localizedDescription ?? "none") + let debugInfo = "NFC: '" + subCmd.description + " command response " + response.count.description + " bytes : 0x" + response.toHexString() + ", error: " + error.debugDescription xdrip.trace("%{public}@", log: self.log, category: ConstantsLog.categoryLibreNFC, type: .info, debugInfo) From 132b14a38f1ca169034cb0ec6ec4c5b59a054c08 Mon Sep 17 00:00:00 2001 From: Guido Soranzio <7220550+gui-dos@users.noreply.github.com> Date: Fri, 12 Jul 2024 07:49:55 +0200 Subject: [PATCH 2/3] =?UTF-8?q?New=20libreview.io=20subdomain=20for=20the?= =?UTF-8?q?=20region=20=E2=80=9Cla=E2=80=9D=20(Latin=20America)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According the Android Brazilian xDrip user @diego-castilho, there is a new `libreview.io` region, “LA”, very probably for “Latin America”. In fact, if you request https://api.libreview.io/llu/config/country?country=BR changing the country code for example for AR, CO or MX you keep on getting the entry `”lslApi":"https://api-la.libreview.io/“` (https://github.com/timoschlueter/nightscout-librelink-up/issues/148) --- xdrip/Managers/LibreLinkUp/LibreLinkUpModels.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xdrip/Managers/LibreLinkUp/LibreLinkUpModels.swift b/xdrip/Managers/LibreLinkUp/LibreLinkUpModels.swift index 3920cd4b1..0b5e6f70f 100644 --- a/xdrip/Managers/LibreLinkUp/LibreLinkUpModels.swift +++ b/xdrip/Managers/LibreLinkUp/LibreLinkUpModels.swift @@ -27,7 +27,8 @@ public enum LibreLinkUpRegion: Int, CaseIterable { case eu2 = 7 case fr = 8 case jp = 9 - case us = 10 + case la = 10 + case us = 11 init?() { @@ -56,6 +57,8 @@ public enum LibreLinkUpRegion: Int, CaseIterable { self = .fr case "jp": self = .jp + case "la": + self = .la case "us": self = .us default: @@ -88,6 +91,8 @@ public enum LibreLinkUpRegion: Int, CaseIterable { return "France" case .jp: return "Japan" + case .la: + return "Latin America" case .us: return "United States" @@ -165,8 +170,10 @@ public enum LibreLinkUpRegion: Int, CaseIterable { return 8 case 9:// jp return 9 - case 10:// us + case 10:// la return 10 + case 11:// us + return 11 default: fatalError("in libreLinkUpRawValue, unknown case") } From 13e4a1e7418364fbdb68e5bd54cac888fd2eb9b8 Mon Sep 17 00:00:00 2001 From: Guido Soranzio <7220550+gui-dos@users.noreply.github.com> Date: Fri, 12 Jul 2024 08:06:05 +0200 Subject: [PATCH 3/3] Add Account-Id HTTP header (user Id's SHA256) required by LLU 4.11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you set “4.11.0” as the LibreLinkUp version in the Developer Settings, you receive the reply `{“message":"RequiredHeaderMissing”}` (status 400) since the recent update of the last week requires a new `Account-Id` HTTP header and you have to pass the SHA256 digest of `libreLinkUpId` as a 64-char hexadecimal string. --- xdrip/Constants/ConstantsLibreLinkUp.swift | 2 +- xdrip/Extensions/String.swift | 5 +++++ xdrip/Managers/LibreLinkUp/LibreLinkUpFollowManager.swift | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/xdrip/Constants/ConstantsLibreLinkUp.swift b/xdrip/Constants/ConstantsLibreLinkUp.swift index 8c0913530..f3bceebde 100644 --- a/xdrip/Constants/ConstantsLibreLinkUp.swift +++ b/xdrip/Constants/ConstantsLibreLinkUp.swift @@ -11,7 +11,7 @@ import Foundation enum ConstantsLibreLinkUp { /// string to hold the default LibreLinkUp version number - static let libreLinkUpVersionDefault: String = "4.7.0" + static let libreLinkUpVersionDefault: String = "4.11.0" /// double to hold maximum sensor days for Libre sensors that upload to LibreLinkUp /// currently easy as they are all the same at 14 days exactly (LibreLink doesn't upload the extra 12 hours) diff --git a/xdrip/Extensions/String.swift b/xdrip/Extensions/String.swift index 164ab8d4f..9566e2047 100644 --- a/xdrip/Extensions/String.swift +++ b/xdrip/Extensions/String.swift @@ -61,6 +61,11 @@ extension String { // sha1() here is a function in CryptoSwift Library return Data(self.utf8).sha1().hexEncodedString() } + + func sha256() -> String { + // sha256() here is a function in CryptoSwift Library + return Data(self.utf8).sha256().hexEncodedString() + } /// creates uicolor interpreting hex as hex color code, example #CED430 func hexStringToUIColor () -> UIColor { diff --git a/xdrip/Managers/LibreLinkUp/LibreLinkUpFollowManager.swift b/xdrip/Managers/LibreLinkUp/LibreLinkUpFollowManager.swift index 997e47341..6dbebc560 100644 --- a/xdrip/Managers/LibreLinkUp/LibreLinkUpFollowManager.swift +++ b/xdrip/Managers/LibreLinkUp/LibreLinkUpFollowManager.swift @@ -572,6 +572,7 @@ class LibreLinkUpFollowManager: NSObject { // this is pretty much the same request as done in requestLogin() var request = URLRequest(url: url) request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") + request.setValue((libreLinkUpId ?? "").sha256(), forHTTPHeaderField: "Account-Id") for (header, value) in libreLinkUpRequestHeaders { request.setValue(value, forHTTPHeaderField: header) @@ -627,6 +628,7 @@ class LibreLinkUpFollowManager: NSObject { // this is pretty much the same request as done in loginRequest() var request = URLRequest(url: url) request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") + request.setValue((libreLinkUpId ?? "").sha256(), forHTTPHeaderField: "Account-Id") for (header, value) in libreLinkUpRequestHeaders { request.setValue(value, forHTTPHeaderField: header)