From 1a215cc608cda982995cd6db2ed9804086cc3012 Mon Sep 17 00:00:00 2001 From: Arthur Ariel Sabintsev Date: Sat, 22 Sep 2018 15:41:32 -0400 Subject: [PATCH] Converted SirenAlertMessaging strings to type of NSAttributedString (#228) * Converted SirenAlertMessaging strings to type of NSAttributedString * Updated documentation * Removed whitespace * Removed more whitespace * Updated sample code and README * Updated sample code and README * Updated sample code and README * Added some docs * Updated Gems * Updated podspec --- Example/Example/AppDelegate.swift | 12 ++++----- Gemfile.lock | 2 +- README.md | 41 ++++++++++++++++--------------- Siren.podspec | 2 +- Sources/Siren.swift | 22 +++++++++-------- Sources/SirenAlertMessaging.swift | 33 ++++++++++++------------- Sources/SirenDelegate.swift | 2 ++ 7 files changed, 59 insertions(+), 55 deletions(-) diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 2f174870..fb24f4fa 100755 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -35,12 +35,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // siren.appName = "Test App Name" // Optional - Change the various UIAlertController and UIAlertAction messaging. One or more values can be changes. If only a subset of values are changed, the defaults with which Siren comes with will be used. -// siren.alertMessaging = SirenAlertMessaging(updateTitle: "New Fancy Title", -// updateMessage: "New message goes here!", -// updateButtonMessage: "Update Now, Plz!?", -// nextTimeButtonMessage: "OK, next time it is!", -// skipVersionButtonMessage: "Please don't push skip, please don't!") - +// siren.alertMessaging = SirenAlertMessaging(updateTitle: NSAttributedString(string: "New Fancy Title"), +// updateMessage: NSAttributedString(string: "New message goes here!"), +// updateButtonMessage: NSAttributedString(string: "Update Now, Plz!?"), +// nextTimeButtonMessage: NSAttributedString(string: "OK, next time it is!"), +// skipVersionButtonMessage: NSAttributedString(string: "Please don't push skip, please don't!")) + // Optional - Defaults to .Option // siren.alertType = .option // or .force, .skip, .none diff --git a/Gemfile.lock b/Gemfile.lock index 2b259bd3..5490f76c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,7 +79,7 @@ GEM rubygems-bundler (1.4.5) bundler-unload (>= 1.0.2) executable-hooks (>= 1.5.0) - sass (3.5.7) + sass (3.6.0) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) diff --git a/README.md b/README.md index d1eb388b..6670a4d0 100755 --- a/README.md +++ b/README.md @@ -104,27 +104,28 @@ For a full list of optional settings/preferences, please refer to https://github func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { /* Siren code should go below window?.makeKeyAndVisible() */ - // Siren is a singleton - let siren = Siren.shared + // Siren is a singleton + let siren = Siren.shared - // Optional: Defaults to .option - siren.alertType = <#Siren.AlertType_Enum_Value#> + // Optional: Defaults to .option + siren.alertType = <#Siren.AlertType_Enum_Value#> - // Optional: Change the various UIAlertController and UIAlertAction messaging. One or more values can be changes. If only a subset of values are changed, the defaults with which Siren comes with will be used. - siren.alertMessaging = SirenAlertMessaging(updateTitle: "New Fancy Title", - updateMessage: "New message goes here!", - updateButtonMessage: "Update Now, Plz!?", - nextTimeButtonMessage: "OK, next time it is!", - skipVersionButtonMessage: "Please don't push skip, please don't!") + // Optional: Change the various UIAlertController and UIAlertAction messaging. One or more values can be changes. If only a subset of values are changed, the defaults with which Siren comes with will be used. + siren.alertMessaging = SirenAlertMessaging(updateTitle: NSAttributedString(string: "New Fancy Title"), + updateMessage: NSAttributedString(string: "New message goes here!"), + updateButtonMessage: NSAttributedString(string: "Update Now, Plz!?"), + nextTimeButtonMessage: NSAttributedString(string: "OK, next time it is!"), + skipVersionButtonMessage: NSAttributedString(string: "Please don't push skip, please don't!")) - // Optional: Set this variable if you would only like to show an alert if your app has been available on the store for a few days. - // This default value is set to 1 to avoid this issue: https://github.com/ArtSabintsev/Siren#words-of-caution - // To show the update immediately after Apple has updated their JSON, set this value to 0. Not recommended due to aforementioned reason in https://github.com/ArtSabintsev/Siren#words-of-caution. - siren.showAlertAfterCurrentVersionHasBeenReleasedForDays = 3 - // Replace .immediately with .daily or .weekly to specify a maximum daily or weekly frequency for version checks. - // DO NOT CALL THIS METHOD IN didFinishLaunchingWithOptions IF YOU ALSO PLAN TO CALL IT IN applicationDidBecomeActive. - siren.checkVersion(checkType: .immediately) + // Optional: Set this variable if you would only like to show an alert if your app has been available on the store for a few days. + // This default value is set to 1 to avoid this issue: https://github.com/ArtSabintsev/Siren#words-of-caution + // To show the update immediately after Apple has updated their JSON, set this value to 0. Not recommended due to aforementioned reason in https://github.com/ArtSabintsev/Siren#words-of-caution. + siren.showAlertAfterCurrentVersionHasBeenReleasedForDays = 3 + + // Replace .immediately with .daily or .weekly to specify a maximum daily or weekly frequency for version checks. + // DO NOT CALL THIS METHOD IN didFinishLaunchingWithOptions IF YOU ALSO PLAN TO CALL IT IN applicationDidBecomeActive. + siren.checkVersion(checkType: .immediately) return true } @@ -167,9 +168,9 @@ func application(application: UIApplication, didFinishLaunchingWithOptions launc extension AppDelegate: SirenDelegate { // Returns a localized message to this delegate method upon performing a successful version check - func sirenDidDetectNewVersionWithoutAlert(message: String, updateType: UpdateType) { - print("\(message)") - } + func sirenDidDetectNewVersionWithoutAlert(message: String, updateType: UpdateType) { + print("\(message)") + } } ``` diff --git a/Siren.podspec b/Siren.podspec index df85cf09..5add3dee 100755 --- a/Siren.podspec +++ b/Siren.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| # Version - s.version = "3.5.1" + s.version = "3.6.0" s.swift_version = '4.2' # Meta diff --git a/Sources/Siren.swift b/Sources/Siren.swift index 8aa08156..9f69a396 100644 --- a/Sources/Siren.swift +++ b/Sources/Siren.swift @@ -161,13 +161,11 @@ public final class Siren: NSObject { } } } - } // MARK: - Helpers (Networking) private extension Siren { - func performVersionCheck() { do { let url = try iTunesURLFromString() @@ -290,7 +288,8 @@ private extension Siren { func showAlert() { storeVersionCheckDate() - let updateAvailableMessage = Bundle.localizedString(forKey: alertMessaging.updateTitle, forceLanguageLocalization: forceLanguageLocalization) + let updateAvailableMessage = Bundle.localizedString(forKey: alertMessaging.updateTitle.string, + forceLanguageLocalization: forceLanguageLocalization) let newVersionMessage = localizedNewVersionMessage() @@ -411,13 +410,13 @@ private extension Siren { private extension Siren { func localizedUpdateTitle() -> String { - let updateTitleToLocalize = alertMessaging.updateTitle - return Bundle.localizedString(forKey: updateTitleToLocalize, forceLanguageLocalization: forceLanguageLocalization) + return Bundle.localizedString(forKey: alertMessaging.updateTitle.string, + forceLanguageLocalization: forceLanguageLocalization) } func localizedNewVersionMessage() -> String { - let newVersionMessageToLocalize = alertMessaging.updateMessage - let newVersionMessage = Bundle.localizedString(forKey: newVersionMessageToLocalize, forceLanguageLocalization: forceLanguageLocalization) + let newVersionMessage = Bundle.localizedString(forKey: alertMessaging.updateMessage.string, + forceLanguageLocalization: forceLanguageLocalization) guard let currentAppStoreVersion = currentAppStoreVersion else { return String(format: newVersionMessage, appName, "Unknown") @@ -427,15 +426,18 @@ private extension Siren { } func localizedUpdateButtonTitle() -> String { - return Bundle.localizedString(forKey: alertMessaging.updateButtonMessage, forceLanguageLocalization: forceLanguageLocalization) + return Bundle.localizedString(forKey: alertMessaging.updateButtonMessage.string, + forceLanguageLocalization: forceLanguageLocalization) } func localizedNextTimeButtonTitle() -> String { - return Bundle.localizedString(forKey: alertMessaging.nextTimeButtonMessage, forceLanguageLocalization: forceLanguageLocalization) + return Bundle.localizedString(forKey: alertMessaging.nextTimeButtonMessage.string, + forceLanguageLocalization: forceLanguageLocalization) } func localizedSkipButtonTitle() -> String { - return Bundle.localizedString(forKey: alertMessaging.skipVersionButtonMessage, forceLanguageLocalization: forceLanguageLocalization) + return Bundle.localizedString(forKey: alertMessaging.skipVersionButtonMessage.string, + forceLanguageLocalization: forceLanguageLocalization) } } diff --git a/Sources/SirenAlertMessaging.swift b/Sources/SirenAlertMessaging.swift index 2c253558..ca27dbc8 100644 --- a/Sources/SirenAlertMessaging.swift +++ b/Sources/SirenAlertMessaging.swift @@ -14,33 +14,33 @@ import Foundation /// /// - Warning: Overriding any of these keys will result in the loss of the built-in internationalization that Siren provides. /// -/// As SirenAlertMessaging is a Struct, one _or_ more keys can be modified. Overriding only one string will result in the other keys retaining their default (and internationalizable) values. +/// As `SirenAlertMessaging` is a Struct, one _or_ more keys can be modified. Overriding only one string will result in the other keys retaining their default (and internationalizable) values. public struct SirenAlertMessaging { /// The default constants used for the alert messaging. public struct Constants { /// The button text that conveys the message that the user should be prompted to update next time the app launches. - public static let nextTime = "Next time" + public static let nextTime = NSAttributedString(string: "Next time") /// The text that conveys the message that the the user wants to skip this verison update. - public static let skipVersion = "Skip this version" + public static let skipVersion = NSAttributedString(string: "Skip this version") /// The text that conveys the message that there is an app update available - public static let updateMessage = "A new version of %@ is available. Please update to version %@ now." + public static let updateMessage = NSAttributedString(string: "A new version of %@ is available. Please update to version %@ now.") /// The alert title which defaults to *Update Available*. - public static let updateTitle = "Update Available" + public static let updateTitle = NSAttributedString(string: "Update Available") /// The button text that conveys the message that the user would like to update the app right away. - public static let updateNow = "Update" + public static let updateNow = NSAttributedString(string: "Update") } - let nextTimeButtonMessage: String - let skipVersionButtonMessage: String - let updateButtonMessage: String - let updateMessage: String - let updateTitle: String + let nextTimeButtonMessage: NSAttributedString + let skipVersionButtonMessage: NSAttributedString + let updateButtonMessage: NSAttributedString + let updateMessage: NSAttributedString + let updateTitle: NSAttributedString /// The public initializer /// @@ -50,16 +50,15 @@ public struct SirenAlertMessaging { /// - updateButtonMessage: The `title` field of the Update Button `UIAlertAction`. /// - nextTimeButtonMessage: The `title` field of the Next Time Button `UIAlertAction`. /// - skipVersionButtonMessage: The `title` field of the Skip Button `UIAlertAction`. - public init(updateTitle title: String = Constants.updateTitle, - updateMessage message: String = Constants.updateMessage, - updateButtonMessage: String = Constants.updateNow, - nextTimeButtonMessage: String = Constants.nextTime, - skipVersionButtonMessage: String = Constants.skipVersion) { + public init(updateTitle title: NSAttributedString = Constants.updateTitle, + updateMessage message: NSAttributedString = Constants.updateMessage, + updateButtonMessage: NSAttributedString = Constants.updateNow, + nextTimeButtonMessage: NSAttributedString = Constants.nextTime, + skipVersionButtonMessage: NSAttributedString = Constants.skipVersion) { self.updateTitle = title self.nextTimeButtonMessage = nextTimeButtonMessage self.updateButtonMessage = updateButtonMessage self.updateMessage = message self.skipVersionButtonMessage = skipVersionButtonMessage } - } diff --git a/Sources/SirenDelegate.swift b/Sources/SirenDelegate.swift index 43c84d2c..87e56977 100644 --- a/Sources/SirenDelegate.swift +++ b/Sources/SirenDelegate.swift @@ -42,6 +42,8 @@ public protocol SirenDelegate: NSObjectProtocol { func sirenDidFailVersionCheck(error: Error) /// User presented with an update dialog. + /// + /// - Parameter alertType: The type of alert that was presented. func sirenDidShowUpdateDialog(alertType: Siren.AlertType) /// Siren performed a version check and the latest version was already installed.