This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rearrange files in folders, added ability to check for new versions
- Loading branch information
1 parent
56b587a
commit e5d8182
Showing
72 changed files
with
149 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// AppVersionController.swift | ||
// NPO Live | ||
// | ||
// Created by Bart den Hollander on 08/11/2017. | ||
// Copyright © 2017 Bart den Hollander. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import NPOStream | ||
|
||
enum VersionControllerResult { | ||
case newVersion(String) | ||
case noNewVersion | ||
} | ||
|
||
struct Release: Codable { | ||
var tag_name: String | ||
var name: String | ||
} | ||
|
||
class VersionUtility { | ||
|
||
static let gitHubLatestReleaseURLString = "https://api.github.com/repos/hollanderbart/NPO-Live/releases/latest" | ||
|
||
func checkForNewVersion(_ currentVersion: String, onCompletion: @escaping (VersionControllerResult) -> Void) { | ||
guard let gitHubLatestReleaseURL = URL(string: VersionUtility.gitHubLatestReleaseURLString) else { return } | ||
|
||
getVersionTagFromLatestRelease(gitHubLatestReleaseURL) { (result) in | ||
switch result { | ||
case .success(let version): | ||
if version > currentVersion { | ||
onCompletion(.newVersion(version)) | ||
} else { | ||
onCompletion(.noNewVersion) | ||
} | ||
case .error(let error): | ||
print(error) | ||
} | ||
} | ||
} | ||
|
||
private func getVersionTagFromLatestRelease(_ url: URL, onCompletion: @escaping (Result<String>) -> Void) { | ||
let decoder = JSONDecoder() | ||
let request = NSMutableURLRequest(url: url) | ||
request.httpMethod = "GET" | ||
request.addValue("application/vnd.github.v3+json", forHTTPHeaderField: "Accept") | ||
|
||
let task = URLSession.shared.dataTask(with: request as URLRequest) { (data, _, error) in | ||
if let responseData = data { | ||
do { | ||
let response = try decoder.decode(Release.self, from: responseData) | ||
onCompletion(.success(response.tag_name)) | ||
} catch { | ||
onCompletion(.error(error)) | ||
} | ||
} else { | ||
if let error = error { | ||
onCompletion(.error(error)) | ||
} | ||
} | ||
} | ||
task.resume() | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// AppDelegate.swift | ||
// NPO Live | ||
// | ||
// Created by Maurice van Breukelen on 21-11-15. | ||
// Copyright © 2015 Maurice van Breukelen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
let versionUtility = VersionUtility() | ||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | ||
|
||
if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { | ||
versionUtility.checkForNewVersion(currentVersion) { result in | ||
switch result { | ||
case .newVersion(let newVersion): | ||
let alert = UIAlertController(title: "Update available", message: "Version \(newVersion) is available. Your version is \(currentVersion).", preferredStyle: UIAlertControllerStyle.alert) | ||
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil)) | ||
|
||
DispatchQueue.main.async { | ||
if let rootViewController = self.window?.rootViewController { | ||
rootViewController.present(alert, animated: true, completion: nil) | ||
} | ||
} | ||
case .noNewVersion: | ||
break | ||
} | ||
|
||
} | ||
} | ||
return true | ||
} | ||
} |
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters