let contentList = result.split(separator: "\r\n") for contentItem in contentList { if contentItem.contains("location") { let tag = contentItem.split(separator: "/").last! if tag.first =="v" { Logger(.Info, "The latest version is \(tag).") latestVersion = tag.dropFirst().lowercased() } } } }
@IBActionfuncupdateMenuItemSelected(_sender: NSMenuItem) { let infoDict =Bundle.main.infoDictionary let currentVersion = infoDict!["CFBundleShortVersionString"] as!String var latestVersion =String()
let infoView =NSAlert() infoView.alertStyle = .informational
let contentList = result.split(separator: "\r\n") for contentItem in contentList { if contentItem.contains("location") { let tag = contentItem.split(separator: "/").last! if tag.first =="v" { Logger(.Info, "The latest version is \(tag).") latestVersion = tag.dropFirst().lowercased() } } }
if latestVersion.isEmpty { infoView.alertStyle = .critical infoView.messageText ="Error" infoView.informativeText ="Failed to get latest info for YourAPPName." } elseif latestVersion == currentVersion { infoView.messageText ="You're up-to-date!" infoView.informativeText ="YourAPPName \(currentVersion) is the latest version." } else { infoView.messageText ="You're out-of-date!" infoView.informativeText ="Newer version \(currentVersion) is currently avaliable." infoView.addButton(withTitle: "Ignore") infoView.addButton(withTitle: "Update") } let resp = infoView.runModal() if resp == .alertSecondButtonReturn { let siteAddr =URL(string: "YourProductsUrl") NSWorkspace.shared.open(siteAddr!) } }