Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
Provide more information to device lookup API, allowing it to provide…
Browse files Browse the repository at this point in the history
… ranges of possible versions (for busy release weeks) and filter out versions too old for new devices (iPhone 11 can't run 12.4.1)
  • Loading branch information
aydenp committed Sep 20, 2019
1 parent b3d7801 commit 397ad34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Serial/UI/ResultsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ResultsViewController: ThemedTableViewController {
analysis.register { update($0.osFamily?.friendlyName) }
}), ValueRow(title: "Probable Version", value: .async { (update) in
analysis.register { update($0.probableVersion) }
})], header: "Operating System", footer: "The latest software version at the end of the week of manufacture. This may be inaccurate for newly released devices."))
})], header: "Operating System", footer: "The current software version during the device's week of manufacture."))

sections.append(Section(rows: [ActionRow(title: "Open Tech Specs", url: analysis.techSpecsURL, viewController: self), ActionRow(title: "Check Coverage", url: analysis.checkCoverageURL, viewController: self), ActionRow(title: "EveryMac Lookup", url: analysis.everyMacURL, viewController: self)], header: "More Information", footer: nil))

Expand Down
11 changes: 10 additions & 1 deletion SerialKit/SerialAnalysis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import Foundation

public class SerialAnalysis {
private static let deviceLookupAPI = "https://deviceinfo.madebyayden.co"

/// The full serial number being analyzed.
public let serialNumber: String
/// The last digits of the serial number which identify this device's model (Space Grey iPhone X, etc)
Expand Down Expand Up @@ -102,8 +104,15 @@ public class SerialAnalysis {
probableVersion = nil
// Cancel any currently running tasks to find the version
probableVersionTask?.cancel()

// Construct the URL (this is kinda hard to read)
guard let platform = osFamily?.rawValue, let weekEnd = manufactureDate?.endDate?.timeIntervalSince1970, let url = URL(string: "https://deviceinfo.madebyayden.co/\(platform)/\(Int(weekEnd))") else { return }
guard let platform = osFamily?.rawValue,
let weekStart = manufactureDate?.startDate?.timeIntervalSince1970,
let weekEnd = manufactureDate?.endDate?.timeIntervalSince1970,
let devicePart = deviceName?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let url = URL(string: "\(SerialAnalysis.deviceLookupAPI)/\(platform)/\(Int(weekStart))/\(Int(weekEnd))?device=\(devicePart)")
else { return }

// Fetch the version!
probableVersionTask = URLSession.shared.dataTask(with: url) { (data, response, error) in
// The response is just the version in plain text, so just decode it to a string
Expand Down

0 comments on commit 397ad34

Please sign in to comment.