From c34245ff211e9a29eb5d23bdb337e5974ccea5a7 Mon Sep 17 00:00:00 2001 From: Joseph Mattello Date: Wed, 16 Nov 2022 17:51:13 -0500 Subject: [PATCH] FetchAnisetteDataOperation.swift fix url reading Signed-off-by: Joseph Mattello --- .../FetchAnisetteDataOperation.swift | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/AltStore/Operations/FetchAnisetteDataOperation.swift b/AltStore/Operations/FetchAnisetteDataOperation.swift index cf7c3bce..298a8fe2 100644 --- a/AltStore/Operations/FetchAnisetteDataOperation.swift +++ b/AltStore/Operations/FetchAnisetteDataOperation.swift @@ -32,34 +32,31 @@ class FetchAnisetteDataOperation: ResultOperation return } - let urlString = UserDefaults.standard.string(forKey: "customAnisetteURL")! - print("Anisette URL: " + urlString) - guard let url = URL(string: urlString) else { return } - - let task = URLSession.shared.dataTask(with: url) { data, response, error in - - guard let data = data, error == nil else { return } - - do { - // make sure this JSON is in the format we expect - // convert data to json - if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] { - // try to read out a dictionary - //for some reason serial number isn't needed but it doesn't work unless it has a value - let formattedJSON: [String: String] = ["machineID": json["X-Apple-I-MD-M"]!, "oneTimePassword": json["X-Apple-I-MD"]!, "localUserID": json["X-Apple-I-MD-LU"]!, "routingInfo": json["X-Apple-I-MD-RINFO"]!, "deviceUniqueIdentifier": json["X-Mme-Device-Id"]!, "deviceDescription": json["X-MMe-Client-Info"]!, "date": json["X-Apple-I-Client-Time"]!, "locale": json["X-Apple-Locale"]!, "timeZone": json["X-Apple-I-TimeZone"]!, "deviceSerialNumber": "1"] - - if let anisette = ALTAnisetteData(json: formattedJSON) { - self.finish(.success(anisette)) - } - } - } catch let error as NSError { - print("Failed to load: \(error.localizedDescription)") - self.finish(.failure(error)) - } - - } - - task.resume() - + let url = AnisetteManager.currentURL + DLOG("Anisette URL: %@", url.absoluteString) + + let task = URLSession.shared.dataTask(with: url) { data, response, error in + guard let data = data, error == nil else { return } + + do { + // make sure this JSON is in the format we expect + // convert data to json + if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] { + // try to read out a dictionary + //for some reason serial number isn't needed but it doesn't work unless it has a value + let formattedJSON: [String: String] = ["machineID": json["X-Apple-I-MD-M"]!, "oneTimePassword": json["X-Apple-I-MD"]!, "localUserID": json["X-Apple-I-MD-LU"]!, "routingInfo": json["X-Apple-I-MD-RINFO"]!, "deviceUniqueIdentifier": json["X-Mme-Device-Id"]!, "deviceDescription": json["X-MMe-Client-Info"]!, "date": json["X-Apple-I-Client-Time"]!, "locale": json["X-Apple-Locale"]!, "timeZone": json["X-Apple-I-TimeZone"]!, "deviceSerialNumber": "1"] + + if let anisette = ALTAnisetteData(json: formattedJSON) { + self.finish(.success(anisette)) + } + } + } catch let error as NSError { + print("Failed to load: \(error.localizedDescription)") + self.finish(.failure(error)) + } + + } + + task.resume() } }