Skip to content

Commit

Permalink
Release 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rwbutler committed Aug 8, 2019
1 parent 69be087 commit 10e81e3
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DerivedData
*.key
# Bundler
.bundle
.build/**

# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Expand Down
8 changes: 7 additions & 1 deletion Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Target Support Files/Updates/Info.plist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version:5.0
import PackageDescription

let package = Package(
name: "Updates",
platforms: [
.iOS("9.0")
],
products: [
.library(
name: "Updates",
targets: ["Updates"]
)
],
targets: [
/*.target(
name: "UpdatesUI",
dependencies: ["Updates"],
path: "Updates/Classes/UI"
),*/
.target(
name: "Updates",
dependencies: [],
path: "Updates/Classes",
exclude: ["UI"]
)
]
)
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![License](https://img.shields.io/cocoapods/l/Updates.svg?style=flat)](https://cocoapods.org/pods/Updates)
[![Platform](https://img.shields.io/cocoapods/p/Updates.svg?style=flat)](https://cocoapods.org/pods/Updates)
[![Swift 5.0](https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat)](https://swift.org/)
[![Twitter](https://img.shields.io/badge/twitter-@ross_w_butler-blue.svg?style=flat)](https://twitter.com/ross_w_butler)
[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)

Updates is a framework for automatically detecting app updates and gently prompting users to update.
Expand All @@ -18,6 +19,7 @@ To learn more about how to use Updates, take a look at the [keynote presentation
- [Installation](#installation)
- [Cocoapods](#cocoapods)
- [Carthage](#carthage)
- [Swift Package Manager](#swift-package-manager)
- [How It Works](#how-it-works)
- [Usage](#usage)
- [Configuration](#configuration)
Expand Down Expand Up @@ -93,6 +95,20 @@ From the macOS Terminal run `carthage update --platform iOS` to build the framew

For more information [see here](https://github.com/Carthage/Carthage#quick-start).

### Swift Package Manager

The [Swift Package Manager](https://swift.org/package-manager/) is a dependency manager for Swift modules and is included as part of the build system as of Swift 3.0. It is used to automate the download, compilation and linking of dependencies.

To include Updates as a dependency within a Swift package, add the package to the `dependencies` entry in your `Package.swift` file as follows:

```swift
dependencies: [
.package(url: "https://github.com/rwbutler/Updates.git", from: "1.0.0")
]
```

* Note that the `UpdatesUI` component is not available as part of the SPM package but will be made available on official release of Xcode 11.

## How It Works
Updates is a framework which automatically checks to see whether a new version of your app is available. When an update is released, Updates is able to present the new version number and accompanying release notes to the user giving them the choice to update. Users electing to proceed are seamlessly presented the App Store in-app so that updating becomes effortless.

Expand Down
2 changes: 1 addition & 1 deletion Updates.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Updates'
s.version = '1.0.0'
s.version = '1.1.0'
s.swift_version = '5.0'
s.summary = 'Updates is a framework for automatically detecting app updates and seamlessly prompting users to update.'
s.description = <<-DESC
Expand Down
14 changes: 9 additions & 5 deletions Updates/Classes/Core/Updates+Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extension Updates {

static func checkForUpdatesAutomatically(comparingVersions
comparator: VersionComparator = Updates.comparingVersions,
currentOSVersion: String,
notifying: NotificationMode = Updates.notifying,
completion: @escaping (UpdatesResult) -> Void) {
DispatchQueue.global(qos: .background).async {
Expand All @@ -66,6 +67,7 @@ extension Updates {
appStoreId = appStoreId ?? String(parsingResult.trackId)
let isUpdateAvailable = isUpdateAvailableForSystemVersion(comparingVersions: comparator,
currentAppVersion: appVersionString,
currentOSVersion: currentOSVersion,
minimumRequiredOS: parsingResult.minimumOsVersion,
newAppVersion: parsingResult.version)
let update = Update(newVersionString: parsingResult.version,
Expand All @@ -79,20 +81,21 @@ extension Updates {
}

static func isUpdateAvailableForSystemVersion(comparingVersions comparator: VersionComparator,
currentAppVersion: String, minimumRequiredOS: String,
currentAppVersion: String, currentOSVersion: String,
minimumRequiredOS: String,
newAppVersion: String) -> Bool {
let isNewVersionAvailable = updateAvailable(appVersion: currentAppVersion, apiVersion: newAppVersion,
comparator: comparator)
let isRequiredOSAvailable = systemVersionAvailable(minimumRequiredOS)
let isRequiredOSAvailable = systemVersionAvailable(currentOSVersion: currentOSVersion,
requiredVersionString: minimumRequiredOS)
return isNewVersionAvailable && isRequiredOSAvailable
}

static func checkForUpdatesManually(appStoreId: String,
comparingVersions comparator: VersionComparator = Updates.comparingVersions,
newVersionString: String,
currentOSVersion: String, newVersionString: String,
notifying: NotificationMode = Updates.notifying,
minimumOSVersion: String,
releaseNotes: String?,
minimumOSVersion: String, releaseNotes: String?,
completion: @escaping (UpdatesResult) -> Void) {
DispatchQueue.global(qos: .background).async {
guard let appVersionString = versionString else {
Expand All @@ -104,6 +107,7 @@ extension Updates {
self.appStoreId = appStoreId
let isUpdateAvailable = isUpdateAvailableForSystemVersion(comparingVersions: comparator,
currentAppVersion: appVersionString,
currentOSVersion: currentOSVersion,
minimumRequiredOS: minimumOSVersion,
newAppVersion: newVersionString)
let update = Update(newVersionString: newVersionString, releaseNotes: releaseNotes,
Expand Down
32 changes: 18 additions & 14 deletions Updates/Classes/Core/Updates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class Updates {

public static var bundleIdentifier: String? = Bundle.main.bundleIdentifier

public static func checkForUpdates(completion: @escaping (UpdatesResult) -> Void) {
public static func checkForUpdates(currentOSVersion: String, completion: @escaping (UpdatesResult) -> Void) {

// Check for updates using settings in configuration JSON
if let configurationURL = configurationURL {
Expand All @@ -68,32 +68,35 @@ public class Updates {
case .success(let configuration):
cacheConfiguration(configuration)
checkForUpdates(configuration.updatingMode, comparingVersions: configuration.comparator,
notifying: configuration.notificationMode, releaseNotes: configuration.releaseNotes,
currentOSVersion: currentOSVersion, notifying: configuration.notificationMode,
releaseNotes: configuration.releaseNotes,
completion: completion)
case .failure:
// Attempt to use last cached configuration first
if let cachedConfigurationURL = cachedConfigurationURL,
let cachedData = try? Data(contentsOf: cachedConfigurationURL),
case let .success(configuration) = ConfigurationJSONParsingService().parse(cachedData) {
checkForUpdates(configuration.updatingMode, comparingVersions: configuration.comparator,
notifying: configuration.notificationMode,
currentOSVersion: currentOSVersion, notifying: configuration.notificationMode,
releaseNotes: configuration.releaseNotes, completion: completion)
} else {
// Fallback to programmatic settings
checkForUpdates(Updates.updatingMode, comparingVersions: comparingVersions,
notifying: notifying, releaseNotes: releaseNotes, completion: completion)
currentOSVersion: currentOSVersion, notifying: notifying,
releaseNotes: releaseNotes, completion: completion)
}
}
}
} else {
// Check for updates using programmatic settings
checkForUpdates(updatingMode, comparingVersions: comparingVersions, notifying: notifying,
completion: completion)
checkForUpdates(updatingMode, comparingVersions: comparingVersions, currentOSVersion: currentOSVersion,
notifying: notifying, completion: completion)
}
}

public static func checkForUpdates(_ mode: UpdatingMode = Updates.updatingMode,
comparingVersions comparator: VersionComparator = Updates.comparingVersions,
currentOSVersion: String,
notifying: NotificationMode = Updates.notifying,
releaseNotes: String? = nil,
completion: @escaping (UpdatesResult) -> Void) {
Expand All @@ -104,7 +107,7 @@ public class Updates {

switch updatingMode {
case .automatically:
checkForUpdatesAutomatically(completion: completion)
checkForUpdatesAutomatically(currentOSVersion: currentOSVersion, completion: completion)
case .manually:
guard let appStoreId = self.appStoreId, let minimumOSVersion = self.minimumOSVersion,
let newVersionString = self.newVersionString else {
Expand All @@ -113,13 +116,13 @@ public class Updates {
minimum required OS version and version string for the new app version.
"""
print(diagnosticMessage)
checkForUpdatesAutomatically(completion: completion)
checkForUpdatesAutomatically(currentOSVersion: currentOSVersion, completion: completion)
return
}
checkForUpdatesManually(appStoreId: appStoreId, comparingVersions: comparator,
newVersionString: newVersionString, notifying: notifying,
minimumOSVersion: minimumOSVersion, releaseNotes: releaseNotes,
completion: completion)
currentOSVersion: currentOSVersion, newVersionString: newVersionString,
notifying: notifying, minimumOSVersion: minimumOSVersion,
releaseNotes: releaseNotes, completion: completion)
case .never:
completion(.none)
}
Expand All @@ -144,9 +147,9 @@ public class Updates {
public static var releaseNotes: String?

/// Determines whether the required version of iOS is available on the current device.
@objc public static func systemVersionAvailable(_ systemVersionString: String) -> Bool {
let currentOSVersion = UIDevice.current.systemVersion
let comparisonResult = compareVersions(lhs: systemVersionString, rhs: currentOSVersion, comparator: .patch)
/// - parameter currentOSVersion The current version of iOS as determined by `UIDevice.current.systemVersion`.
@objc public static func systemVersionAvailable(currentOSVersion: String, requiredVersionString: String) -> Bool {
let comparisonResult = compareVersions(lhs: requiredVersionString, rhs: currentOSVersion, comparator: .patch)
return comparisonResult != .orderedDescending
}

Expand All @@ -155,4 +158,5 @@ public class Updates {
internal static let userDefaultsKey = "com.rwbutler.updates"

public static let versionString: String? = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String

}
25 changes: 25 additions & 0 deletions Updates/Classes/UI/Updates+UIDevice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Updates+UIDevice.swift
// Updates
//
// Created by Ross Butler on 8/8/19.
//

import Foundation

public extension Updates {

static func checkForUpdates(completion: @escaping (UpdatesResult) -> Void) {
Updates.checkForUpdates(currentOSVersion: UIDevice.current.systemVersion, completion: completion)
}

static func checkForUpdates(_ mode: UpdatingMode = Updates.updatingMode,
comparingVersions comparator: VersionComparator = Updates.comparingVersions,
notifying: NotificationMode = Updates.notifying,
releaseNotes: String? = nil,
completion: @escaping (UpdatesResult) -> Void) {
checkForUpdates(mode, comparingVersions: comparator, currentOSVersion: UIDevice.current.systemVersion,
notifying: notifying, releaseNotes: releaseNotes, completion: completion)
}

}

0 comments on commit 10e81e3

Please sign in to comment.