Skip to content

Commit

Permalink
Fixed same version bug found in #288 (#289)
Browse files Browse the repository at this point in the history
* Fixed bug found in #288

* Adds throwable function to handle same version error

* Updates docs
  • Loading branch information
ArtSabintsev authored May 15, 2019
1 parent 2284e63 commit cb1febd
Show file tree
Hide file tree
Showing 81 changed files with 4,240 additions and 5,811 deletions.
2 changes: 1 addition & 1 deletion Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@
children = (
8EF9F865224EACB100B20545 /* AlertAction.swift */,
8EF9F866224EACB100B20545 /* AlertConstants.swift */,
8EF9F869224EACB100B20545 /* APIModel.swift */,
8EF9F867224EACB100B20545 /* Localization.swift */,
8EF9F868224EACB100B20545 /* Model.swift */,
8EF9F869224EACB100B20545 /* APIModel.swift */,
8EF9F86A224EACB100B20545 /* Rules.swift */,
8EF9F86B224EACB100B20545 /* PerformCheck.swift */,
8EF9F86C224EACB100B20545 /* UpdateResults.swift */,
Expand Down
4 changes: 2 additions & 2 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
/// Siren initializes a listener on `didBecomeActiveNotification` to perform version checks.

// defaultExample()
defaultExampleUsingCompletionHandler()
// defaultExampleUsingCompletionHandler()
// manualExampleWithCompletionHandler()
// minimalCustomizationPresentationExample()
// forceLocalizationCustomizationPresentationExample()
// customMessagingPresentationExample()
// annoyingRuleExample()
annoyingRuleExample()
// hyperCriticalRulesExample()
// updateSpecificRulesExample()
// customAlertRulesExample()
Expand Down
2 changes: 1 addition & 1 deletion Example/Siren/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down
7 changes: 4 additions & 3 deletions Sources/Managers/RulesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ public struct RulesManager {

/// Returns the appropriate update rules based on the type of version that is returned from the API.
///
/// - Parameter type: The type of app update.
/// - Parameters: type: The type of app update.
/// - Throws: The `noUpdateAvailable` error since this is the only way a valie of `unknown` can occur.
/// - Returns: The appropriate rule based on the type of app update that is returned by the API.
func loadRulesForUpdateType(_ type: UpdateType) -> Rules {
func loadRulesForUpdateType(_ type: UpdateType) throws -> Rules {
switch type {
case .major: return majorUpdateRules
case .minor: return minorUpdateRules
case .patch: return patchUpdateRules
case .revision: return revisionUpdateRules
case .unknown: return majorUpdateRules
case .unknown: throw KnownError.noUpdateAvailable
}
}

Expand Down
26 changes: 16 additions & 10 deletions Sources/Siren.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,26 @@ private extension Siren {

let updateType = DataParser.parseForUpdate(forInstalledVersion: currentInstalledVersion,
andAppStoreVersion: currentAppStoreVersion)
let rules = rulesManager.loadRulesForUpdateType(updateType)
do {
let rules = try rulesManager.loadRulesForUpdateType(updateType)

if rules.frequency == .immediately {
presentAlert(withRules: rules, forCurrentAppStoreVersion: currentAppStoreVersion, model: model, andUpdateType: updateType)
} else {
guard let alertPresentationDate = alertPresentationDate else {
presentAlert(withRules: rules, forCurrentAppStoreVersion: currentAppStoreVersion, model: model, andUpdateType: updateType)
return
}
if Date.days(since: alertPresentationDate) >= rules.frequency.rawValue {
if rules.frequency == .immediately {
presentAlert(withRules: rules, forCurrentAppStoreVersion: currentAppStoreVersion, model: model, andUpdateType: updateType)
} else {
resultsHandler?(.failure(.recentlyPrompted))
guard let alertPresentationDate = alertPresentationDate else {
presentAlert(withRules: rules, forCurrentAppStoreVersion: currentAppStoreVersion, model: model, andUpdateType: updateType)
return
}
if Date.days(since: alertPresentationDate) >= rules.frequency.rawValue {
presentAlert(withRules: rules, forCurrentAppStoreVersion: currentAppStoreVersion, model: model, andUpdateType: updateType)
} else {
resultsHandler?(.failure(.recentlyPrompted))
}
}
} catch let error as KnownError {
resultsHandler?(.failure(error))
} catch { // This path should never be entered, but this silences an error.
resultsHandler?(.failure(.noUpdateAvailable))
}
}

Expand Down
134 changes: 56 additions & 78 deletions docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,166 +4,145 @@
<title>Classes Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset="utf-8">
<meta charset='utf-8'>
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>

<script src="js/lunr.min.js" defer></script>
<script src="js/typeahead.jquery.js" defer></script>
<script src="js/jazzy.search.js" defer></script>
</head>
<body>

<a name="//apple_ref/swift/Section/Classes" class="dashAnchor"></a>

<a title="Classes Reference"></a>

<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="index.html">
Siren Docs
</a>
(100% documented)
</p>

<p class="header-col--secondary">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</p>


<header>
<div class="content-wrapper">
<p><a href="index.html">Siren Docs</a> (100% documented)</p>
</div>
</header>

<p class="breadcrumbs">
<a class="breadcrumb" href="index.html">Siren Reference</a>
<img class="carat" src="img/carat.png" />
Classes Reference
</p>

<div class="content-wrapper">
<nav class="navigation">
<p id="breadcrumbs">
<a href="index.html">Siren Reference</a>
<img id="carat" src="img/carat.png" />
Classes Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a class="nav-group-name-link" href="Classes.html">Classes</a>
<a href="Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/Siren.html">Siren</a>
<a href="Classes/Siren.html">Siren</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/SirenViewController.html">SirenViewController</a>
<a href="Classes/SirenViewController.html">SirenViewController</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Enums.html">Enumerations</a>
<a href="Enums.html">Enumerations</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/AlertAction.html">AlertAction</a>
<a href="Enums/AlertAction.html">AlertAction</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/KnownError.html">KnownError</a>
<a href="Enums/KnownError.html">KnownError</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/PerformCheck.html">PerformCheck</a>
<a href="Enums/PerformCheck.html">PerformCheck</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Extensions.html">Extensions</a>
<a href="Extensions.html">Extensions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/Bundle.html">Bundle</a>
<a href="Extensions/Bundle.html">Bundle</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/Bundle/Constants.html">– Constants</a>
<a href="Extensions/Bundle/Constants.html">– Constants</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/Date.html">Date</a>
<a href="Extensions/Date.html">Date</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/UIAlertController.html">UIAlertController</a>
<a href="Extensions/UIAlertController.html">UIAlertController</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/UserDefaults.html">UserDefaults</a>
<a href="Extensions/UserDefaults.html">UserDefaults</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/UserDefaults/SirenKeys.html">– SirenKeys</a>
<a href="Extensions/UserDefaults/SirenKeys.html">– SirenKeys</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Structs.html">Structures</a>
<a href="Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/APIManager.html">APIManager</a>
<a href="Structs/APIManager.html">APIManager</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/APIManager/Constants.html">– Constants</a>
<a href="Structs/APIManager/Constants.html">– Constants</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/APIModel.html">APIModel</a>
<a href="Structs/APIModel.html">APIModel</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/APIModel/CodingKeys.html">– CodingKeys</a>
<a href="Structs/APIModel/CodingKeys.html">– CodingKeys</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/APIModel/Results.html">– Results</a>
<a href="Structs/APIModel/Results.html">– Results</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/AlertConstants.html">AlertConstants</a>
<a href="Structs/AlertConstants.html">AlertConstants</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/DataParser.html">DataParser</a>
<a href="Structs/DataParser.html">DataParser</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Localization.html">Localization</a>
<a href="Structs/Localization.html">Localization</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Localization/Language.html">– Language</a>
<a href="Structs/Localization/Language.html">– Language</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Model.html">Model</a>
<a href="Structs/Model.html">Model</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/PresentationManager.html">PresentationManager</a>
<a href="Structs/PresentationManager.html">PresentationManager</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Rules.html">Rules</a>
<a href="Structs/Rules.html">Rules</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Rules/AlertType.html">– AlertType</a>
<a href="Structs/Rules/AlertType.html">– AlertType</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Rules/UpdatePromptFrequency.html">– UpdatePromptFrequency</a>
<a href="Structs/Rules/UpdatePromptFrequency.html">– UpdatePromptFrequency</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/RulesManager.html">RulesManager</a>
<a href="Structs/RulesManager.html">RulesManager</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/RulesManager/UpdateType.html">– UpdateType</a>
<a href="Structs/RulesManager/UpdateType.html">– UpdateType</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/UpdateResults.html">UpdateResults</a>
<a href="Structs/UpdateResults.html">UpdateResults</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">

<section class="section">
<div class="section-content">
<section>
<section class="section">
<h1>Classes</h1>
<p>The following classes are available globally.</p>

</div>
</section>

<section class="section">
<div class="section-content">
</section>
<section class="section task-group-section">
<div class="task-group">
<ul class="item-container">
<ul>
<li class="item">
<div>
<code>
Expand Down Expand Up @@ -195,7 +174,7 @@ <h4>Declaration</h4>
</ul>
</div>
<div class="task-group">
<ul class="item-container">
<ul>
<li class="item">
<div>
<code>
Expand Down Expand Up @@ -226,15 +205,14 @@ <h4>Declaration</h4>
</li>
</ul>
</div>
</div>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="https://github.com/ArtSabintsev/Siren" target="_blank" rel="external">Arthur Ariel Sabintsev</a>. All rights reserved. (Last updated: 2019-05-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>

</article>
</div>
<section class="footer">
<p>&copy; 2019 <a class="link" href="https://github.com/ArtSabintsev/Siren" target="_blank" rel="external">Arthur Ariel Sabintsev</a>. All rights reserved. (Last updated: 2019-04-24)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
</div>
</html>
Loading

0 comments on commit cb1febd

Please sign in to comment.