Skip to content

Commit

Permalink
Converted SirenAlertMessaging strings to type of NSAttributedString (A…
Browse files Browse the repository at this point in the history
…rtSabintsev#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
  • Loading branch information
ArtSabintsev committed Sep 22, 2018
1 parent 7e30501 commit 1a215cc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 55 deletions.
12 changes: 6 additions & 6 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)")
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion Siren.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 12 additions & 10 deletions Sources/Siren.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,11 @@ public final class Siren: NSObject {
}
}
}

}

// MARK: - Helpers (Networking)

private extension Siren {

func performVersionCheck() {
do {
let url = try iTunesURLFromString()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
}

Expand Down
33 changes: 16 additions & 17 deletions Sources/SirenAlertMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -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
}

}
2 changes: 2 additions & 0 deletions Sources/SirenDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1a215cc

Please sign in to comment.