fix(ios): Fixes online help link versioning

This commit is contained in:
jahorton 2020-03-03 14:15:31 +07:00
parent 3fa975ee37
commit a67eb966c4
3 changed files with 31 additions and 2 deletions

View file

@ -40,6 +40,26 @@ public struct Version: Comparable {
self.components = components
}
public init?(_ components: [Int]) {
if components.count == 0 {
return nil
}
var string = ""
for i in components {
guard i >= 0 else {
return nil
}
let dot = (string == "" ? "" : ".")
string = "\(string)\(dot)\(i)"
}
self.string = string
self.components = components // Swift arrays are value types, not reference types!
}
public static func <(lhs: Version, rhs: Version) -> Bool {
let len = max(lhs.components.count, rhs.components.count)
for i in 0..<len {
@ -63,4 +83,13 @@ public struct Version: Comparable {
public var description: String {
return self.string
}
public var majorMinor: Version {
if(self.components.count >= 2) {
return Version([self.components[0], self.components[1]])!
} else {
// If we somehow have just a major version, append a simple '0'.
return Version([self.components[0], 0])!
}
}
}

View file

@ -61,7 +61,7 @@ class InfoViewController: UIViewController, UIWebViewDelegate {
}
private func loadFromServer() {
let appVersion = Version.current
let appVersion = Version.current.majorMinor
let url = "https://help.keyman.com/products/iphone-and-ipad/\(appVersion.string)/?embed=ios"
webView.loadRequest(URLRequest(url: URL(string: url)!))
log.debug("Info page URL: \(url)")

View file

@ -68,7 +68,7 @@ class SetUpViewController: UIViewController, UIWebViewDelegate {
}
private func loadFromServer() {
let appVersion = Version.current
let appVersion = Version.current.majorMinor
let url = "https://help.keyman.com/products/iphone-and-ipad/\(appVersion.string)"
+ "/installing-system-keyboard.php?embed=ios"
webView.loadRequest(URLRequest(url: URL(string: url)!))