Skip to content

Commit 03eb15e

Browse files
authored
Merge pull request #128 from ArtSabintsev/story/swiftier-code
Swifiter Codebase
2 parents d756bc3 + 0d0f488 commit 03eb15e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+7275
-43
lines changed

.jazzy.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module: Siren
2+
author: Arthur Ariel Sabintsev
3+
author_url: http://www.sabintsev.com
4+
github_url: https://github.com/artsabintsev/siren
5+
copyright: "© 2015-2017 [Arthur Ariel Sabintsev](http://www.sabintsev.com)"
6+
clean: true
7+
podspec: Siren.podspec

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
source "https://rubygems.org"
33

44
gem "cocoapods", "1.1.1"
5+
gem "jazzy"

Gemfile.lock

+20-1
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,33 @@ GEM
4747
fuzzy_match (2.0.4)
4848
gh_inspector (1.0.2)
4949
i18n (0.7.0)
50+
jazzy (0.7.4)
51+
cocoapods (~> 1.0)
52+
mustache (~> 0.99)
53+
open4
54+
redcarpet (~> 3.2)
55+
rouge (~> 1.5)
56+
sass (~> 3.4)
57+
sqlite3 (~> 1.3)
58+
xcinvoke (~> 0.3.0)
5059
json (1.8.3)
60+
liferaft (0.0.6)
5161
minitest (5.9.1)
5262
molinillo (0.5.3)
63+
mustache (0.99.8)
5364
nanaimo (0.2.2)
5465
nap (1.1.0)
5566
netrc (0.7.8)
67+
open4 (1.3.4)
68+
redcarpet (3.4.0)
69+
rouge (1.11.1)
70+
sass (3.4.23)
71+
sqlite3 (1.3.13)
5672
thread_safe (0.3.5)
5773
tzinfo (1.2.2)
5874
thread_safe (~> 0.1)
75+
xcinvoke (0.3.0)
76+
liferaft (~> 0.0.6)
5977
xcodeproj (1.4.1)
6078
CFPropertyList (~> 2.3.3)
6179
activesupport (>= 3)
@@ -68,6 +86,7 @@ PLATFORMS
6886

6987
DEPENDENCIES
7088
cocoapods (= 1.1.1)
89+
jazzy
7190

7291
BUNDLED WITH
73-
1.13.6
92+
1.14.5

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### Notify users when a new version of your app is available and prompt them to upgrade.
44

5-
[![BuddyBuild](https://dashboard.buddybuild.com/api/statusImage?appID=58ba28410648b401002b7291&branch=master&build=latest)](https://dashboard.buddybuild.com/apps/58ba28410648b401002b7291/build/latest?branch=master) [![CocoaPods](https://img.shields.io/cocoapods/v/Siren.svg)](https://cocoapods.org/pods/Siren) [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![SwiftPM Compatible](https://img.shields.io/badge/SwiftPM-Compatible-brightgreen.svg)](https://swift.org/package-manager/) [![CocoaPods](https://img.shields.io/cocoapods/dt/Siren.svg)](https://cocoapods.org/pods/Siren) [![CocoaPods](https://img.shields.io/cocoapods/dm/Siren.svg)](https://cocoapods.org/pods/Siren)
5+
[![CocoaPods](https://img.shields.io/cocoapods/v/Siren.svg)](https://cocoapods.org/pods/Siren) [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![SwiftPM Compatible](https://img.shields.io/badge/SwiftPM-Compatible-brightgreen.svg)](https://swift.org/package-manager/) [![CocoaPods](https://img.shields.io/cocoapods/dt/Siren.svg)](https://cocoapods.org/pods/Siren) [![CocoaPods](https://img.shields.io/cocoapods/dm/Siren.svg)](https://cocoapods.org/pods/Siren)
66
---
77

88
## About
@@ -93,7 +93,7 @@ func application(application: UIApplication, didFinishLaunchingWithOptions launc
9393
/* Siren code should go below window?.makeKeyAndVisible() */
9494

9595
// Siren is a singleton
96-
let siren = Siren.sharedInstance
96+
let siren = Siren.shared
9797

9898
// Optional: Defaults to .Option
9999
siren.alertType = <#SirenAlertType_Enum_Value#>
@@ -113,7 +113,7 @@ func applicationDidBecomeActive(application: UIApplication) {
113113
Useful if user returns to your app from the background after extended period of time.
114114
Place in applicationDidBecomeActive(_:). */
115115

116-
Siren.sharedInstance.checkVersion(checkType: .daily)
116+
Siren.shared.checkVersion(checkType: .daily)
117117
}
118118

119119
func applicationWillEnterForeground(application: UIApplication) {
@@ -124,7 +124,7 @@ func applicationWillEnterForeground(application: UIApplication) {
124124
ONLY USE WITH SirenAlertType.Force
125125
*/
126126

127-
Siren.sharedInstance.checkVersion(checkType: .immediately)
127+
Siren.shared.checkVersion(checkType: .immediately)
128128
}
129129
```
130130

@@ -157,10 +157,10 @@ If you would like to set a different type of alert for revision, patch, minor, a
157157

158158
```swift
159159
/* Siren defaults to SirenAlertType.Option for all updates */
160-
siren.sharedInstance().revisionUpdateAlertType = <#SirenAlertType_Enum_Value#>
161-
siren.sharedInstance().patchUpdateAlertType = <#SirenAlertType_Enum_Value#>
162-
siren.sharedInstance().minorUpdateAlertType = <#SirenAlertType_Enum_Value#>
163-
siren.sharedInstance().majorUpdateAlertType = <#SirenAlertType_Enum_Value#>
160+
siren.shared.revisionUpdateAlertType = <#SirenAlertType_Enum_Value#>
161+
siren.shared.patchUpdateAlertType = <#SirenAlertType_Enum_Value#>
162+
siren.shared.minorUpdateAlertType = <#SirenAlertType_Enum_Value#>
163+
siren.shared.majorUpdateAlertType = <#SirenAlertType_Enum_Value#>
164164
```
165165

166166
## Optional Delegate and Delegate Methods
@@ -217,7 +217,7 @@ You may want the update dialog to *always* appear in a certain language, ignorin
217217
You can enable it like this:
218218

219219
```swift
220-
Siren.sharedInstance.forceLanguageLocalization = SirenLanguageType.<#SirenLanguageType_Enum_Value#>
220+
Siren.shared.forceLanguageLocalization = SirenLanguageType.<#SirenLanguageType_Enum_Value#>
221221
```
222222
## Device Compatibility
223223
If an app update is available, Siren checks to make sure that the version of iOS on the user's device is compatible the one that is required by the app update. For example, if a user has iOS 9 installed on their device, but the app update requires iOS 10, an alert will not be shown. This takes care of the *false positive* case regarding app updating.

Siren.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Siren"
3-
s.version = "1.1.3"
3+
s.version = "1.2.0"
44
s.summary = "Notify users when a new version of your iOS app is available, and prompt them with the App Store link.."
55

66
s.description = <<-DESC

Siren/Siren.swift

+50-28
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,28 @@ import UIKit
1010

1111
// MARK: - SirenDelegate Protocol
1212

13+
/// Delegate that handles all codepaths for Siren upon version check completion.
1314
public protocol SirenDelegate: class {
14-
func sirenDidShowUpdateDialog(alertType: SirenAlertType) // User presented with update dialog
15-
func sirenUserDidLaunchAppStore() // User did click on button that launched App Store.app
16-
func sirenUserDidSkipVersion() // User did click on button that skips version update
17-
func sirenUserDidCancel() // User did click on button that cancels update dialog
18-
func sirenDidFailVersionCheck(error: NSError) // Siren failed to perform version check (may return system-level error)
19-
func sirenDidDetectNewVersionWithoutAlert(message: String) // Siren performed version check and did not display alert
20-
func sirenLatestVersionInstalled() // Siren performed version check and latest version is installed
15+
/// User presented with update dialog
16+
func sirenDidShowUpdateDialog(alertType: SirenAlertType)
17+
18+
/// User did click on button that launched App Store.app
19+
func sirenUserDidLaunchAppStore()
20+
21+
/// User did click on button that skips version update
22+
func sirenUserDidSkipVersion()
23+
24+
/// User did click on button that cancels update dialog
25+
func sirenUserDidCancel()
26+
27+
/// Siren failed to perform version check (may return system-level error)
28+
func sirenDidFailVersionCheck(error: NSError)
29+
30+
/// Siren performed version check and did not display alert
31+
func sirenDidDetectNewVersionWithoutAlert(message: String)
32+
33+
/// Siren performed version check and latest version is installed
34+
func sirenLatestVersionInstalled()
2135
}
2236

2337
// MARK: - SirenDelegate Protocol Extension
@@ -33,27 +47,31 @@ public extension SirenDelegate {
3347
}
3448

3549
/// Determines the type of alert to present after a successful version check has been performed.
36-
///
37-
/// - force: Forces user to update your app (1 button alert)
38-
/// - option: (DEFAULT) Presents user with option to update app now or at next launch (2 button alert)
39-
/// - skip: Presents user with option to update the app now, at next launch, or to skip this version all together (3 button alert)
40-
/// - none: Doesn't show the alert, but instead returns a localized message for use in a custom UI within the sirenDidDetectNewVersionWithoutAlert() delegate method
4150
public enum SirenAlertType {
42-
case force // Forces user to update your app (1 button alert)
43-
case option // (DEFAULT) Presents user with option to update app now or at next launch (2 button alert)
44-
case skip // Presents user with option to update the app now, at next launch, or to skip this version all together (3 button alert)
45-
case none // Doesn't show the alert, but instead returns a localized message for use in a custom UI within the sirenDidDetectNewVersionWithoutAlert() delegate method
51+
/// Forces user to update your app (1 button alert).
52+
case force
53+
54+
/// (DEFAULT) Presents user with option to update app now or at next launch (2 button alert).
55+
case option
56+
57+
/// Presents user with option to update the app now, at next launch, or to skip this version all together (3 button alert).
58+
case skip
59+
60+
/// Doesn't show the alert, but instead returns a localized message for use in a custom UI within the sirenDidDetectNewVersionWithoutAlert() delegate method.
61+
case none
4662
}
4763

48-
/// Determines the frequency in which the the version check is performed
64+
/// Determines the frequency in which the the version check is performed.
4965
///
50-
/// - immediately: Version check performed every time the app is launched.
51-
/// - daily: Version check performed once a day.
52-
/// - weekly: Version check performed once a week.
5366
public enum SirenVersionCheckType: Int {
54-
case immediately = 0 // Version check performed every time the app is launched
55-
case daily = 1 // Version check performed once a day
56-
case weekly = 7 // Version check performed once a week
67+
/// Version check performed every time the app is launched.
68+
case immediately = 0
69+
70+
/// Version check performed once a day.
71+
case daily = 1
72+
73+
/// Version check performed once a week.
74+
case weekly = 7
5775
}
5876

5977
/// Determines the available languages in which the update message and alert button titles should appear.
@@ -120,17 +138,17 @@ private enum SirenError: Error {
120138
}
121139

122140
/// Siren-specific UserDefaults Keys
123-
///
124-
/// - StoredVersionCheckDate: Key that stores the timestamp of the last version check
125-
/// - StoredSkippedVersion: Key that stores the version that a user decided to skip
126141
private enum SirenUserDefaults: String {
142+
/// Key that stores the timestamp of the last version check in UserDefaults
127143
case StoredVersionCheckDate
144+
145+
/// Key that stores the version that a user decided to skip in UserDefaults.
128146
case StoredSkippedVersion
129147
}
130148

131149
// MARK: - Siren
132150

133-
/// The Siren Class. A singleton that is initialized using the sharedInstance() method.
151+
/// The Siren Class. A singleton that is initialized using the shared() method.
134152
public final class Siren: NSObject {
135153

136154
///Current installed version of your app
@@ -215,6 +233,10 @@ public final class Siren: NSObject {
215233
fileprivate lazy var alertViewIsVisible: Bool = false
216234
fileprivate var updaterWindow: UIWindow?
217235

236+
/// The App's Singleton
237+
public static let shared = Siren()
238+
239+
@available(*, deprecated: 1.2.0, unavailable, renamed: "shared")
218240
public static let sharedInstance = Siren()
219241

220242
override init() {
@@ -615,7 +637,7 @@ private extension UIAlertController {
615637
window.rootViewController = ViewController()
616638
window.windowLevel = UIWindowLevelAlert + 1
617639

618-
Siren.sharedInstance.updaterWindow = window
640+
Siren.shared.updaterWindow = window
619641

620642
window.makeKeyAndVisible()
621643
window.rootViewController!.present(self, animated: true, completion: nil)

SirenExample/SirenExample/AppDelegate.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2323
}
2424

2525
func setupSiren() {
26-
let siren = Siren.sharedInstance
26+
let siren = Siren.shared
2727

2828
// Optional
2929
siren.delegate = self
@@ -58,12 +58,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5858

5959
func applicationWillEnterForeground(_ application: UIApplication) {
6060
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
61-
Siren.sharedInstance.checkVersion(checkType: .immediately)
61+
Siren.shared.checkVersion(checkType: .immediately)
6262
}
6363

6464
func applicationDidBecomeActive(_ application: UIApplication) {
6565
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
66-
Siren.sharedInstance.checkVersion(checkType: .daily)
66+
Siren.shared.checkVersion(checkType: .daily)
6767
}
6868
}
6969

SirenExample/SirenExampleTests/SirenTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import XCTest
1111

1212
class SirenTests: XCTestCase {
1313

14-
let siren = Siren.sharedInstance
14+
let siren = Siren.shared
1515

1616
}
1717

0 commit comments

Comments
 (0)