Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a second UIWindow to display the UIAlertController. #18

Merged
merged 2 commits into from
May 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Sample App/Sample App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Required
siren.appID = "376771144" // For this example, we're using the iTunes Connect App (https://itunes.apple.com/us/app/itunes-connect/id376771144?mt=8)

// Required
siren.presentingViewController = window?.rootViewController

// Optional
siren.delegate = self

Expand Down
39 changes: 27 additions & 12 deletions Siren/Siren.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,6 @@ public class Siren: NSObject
*/
public var appID: String?

/**
The view controller that will present the instance of UIAlertController.

It is recommended that you set this value to window?.rootViewController.

This property must be set before calling checkVersion().
*/
public var presentingViewController: UIViewController?

// Optional Vars
/**
The name of your app.
Expand Down Expand Up @@ -209,6 +200,7 @@ public class Siren: NSObject
// Private
private var lastVersionCheckPerformedOnDate: NSDate?
private var currentAppStoreVersion: String?
private var updaterWindow: UIWindow!

// MARK: Initialization
public class var sharedInstance: Siren {
Expand All @@ -235,8 +227,6 @@ public class Siren: NSObject

if (appID == nil) {
println("[Siren] Please make sure that you have set 'appID' before calling checkVersion.")
} else if (useAlertController && presentingViewController == nil) { // iOS 8 only
println("[Siren] Please make sure that you have set 'presentingViewController' before calling checkVersion.")
} else {
if checkType == .Immediately {
performVersionCheck()
Expand Down Expand Up @@ -377,7 +367,7 @@ private extension Siren
}

if alertType != .None {
presentingViewController?.presentViewController(alertController, animated: true, completion: nil)
alertController.show()
}

} else { // iOS 7
Expand Down Expand Up @@ -409,6 +399,7 @@ private extension Siren
func updateAlertAction() -> UIAlertAction {
let title = localizedUpdateButtonTitle()
let action = UIAlertAction(title: title, style: .Default) { (alert: UIAlertAction!) -> Void in
self.hideWindow()
self.launchAppStore()
self.delegate?.sirenUserDidLaunchAppStore?()
return
Expand All @@ -420,6 +411,7 @@ private extension Siren
func nextTimeAlertAction() -> UIAlertAction {
let title = localizedNextTimeButtonTitle()
let action = UIAlertAction(title: title, style: .Default) { (alert: UIAlertAction!) -> Void in
self.hideWindow()
self.delegate?.sirenUserDidCancel?()
return
}
Expand All @@ -430,12 +422,35 @@ private extension Siren
func skipAlertAction() -> UIAlertAction {
let title = localizedSkipButtonTitle()
let action = UIAlertAction(title: title, style: .Default) { (alert: UIAlertAction!) -> Void in
self.hideWindow()
self.delegate?.sirenUserDidSkipVersion?()
return
}

return action
}

func hideWindow() {
updaterWindow.hidden = true
updaterWindow = nil
}
}

// MARK: UIAlertController + UIWindow
private extension UIAlertController
{

func show() {
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
window.rootViewController = UIViewController()
window.windowLevel = UIWindowLevelAlert + 1 // make the window appear above all other view controllers and windows

Siren.sharedInstance.updaterWindow = window

window.makeKeyAndVisible()
window.rootViewController?.presentViewController(self, animated: true, completion: nil)
}

}

// MARK: Helpers
Expand Down