mirror of
https://github.com/UrbanApps/Armchair.git
synced 2026-04-24 09:48:36 +02:00
Merge pull request #107 from MartinMoizard/swift3-and-root-fix
Fix issue when `getRootViewController` would return `nil`
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
var window: UIWindow?
|
var window: UIWindow?
|
||||||
|
|
||||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,12 +55,12 @@ extension ViewController {
|
|||||||
|
|
||||||
// Only set it if we are using Armchair localizations
|
// Only set it if we are using Armchair localizations
|
||||||
if !Armchair.useMainAppBundleForLocalizations() {
|
if !Armchair.useMainAppBundleForLocalizations() {
|
||||||
let currentLocalization: NSString = NSBundle.mainBundle().preferredLocalizations[0] as NSString
|
let currentLocalization: NSString = Bundle.main.preferredLocalizations[0] as NSString
|
||||||
// Only set it if we are using a different language than this apps development language
|
// Only set it if we are using a different language than this apps development language
|
||||||
if let developmentLocalization = NSBundle.mainBundle().developmentLocalization {
|
if let developmentLocalization = Bundle.main.developmentLocalization {
|
||||||
if currentLocalization != developmentLocalization {
|
if currentLocalization as String != developmentLocalization {
|
||||||
languageLabelText = currentLocalization as String
|
languageLabelText = currentLocalization as String
|
||||||
if let displayName = NSLocale(localeIdentifier: currentLocalization as String).displayNameForKey(NSLocaleIdentifier, value:currentLocalization) {
|
if let displayName = (Locale(identifier: currentLocalization as String) as NSLocale).displayName(forKey: NSLocale.Key.identifier, value:currentLocalization) {
|
||||||
languageLabelText = "\(displayName): \(currentLocalization)"
|
languageLabelText = "\(displayName): \(currentLocalization)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ extension ViewController {
|
|||||||
Armchair.opensInStoreKit(false)
|
Armchair.opensInStoreKit(false)
|
||||||
|
|
||||||
// This sets a custom tint color (applies only to UIAlertController).
|
// This sets a custom tint color (applies only to UIAlertController).
|
||||||
Armchair.tintColor(UIColor.brownColor())
|
Armchair.tintColor(tintColor: UIColor.brown)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This sets the Affiliate code you want to use, but is not required.
|
// This sets the Affiliate code you want to use, but is not required.
|
||||||
@@ -216,9 +216,9 @@ extension ViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func openUrbanApps(_: AnyObject) {
|
@IBAction func openUrbanApps(_: AnyObject) {
|
||||||
if let url = NSURL(string: "http://urbanapps.com") {
|
if let url = URL(string: "http://urbanapps.com") {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
UIApplication.sharedApplication().openURL(url)
|
UIApplication.shared.openURL(url)
|
||||||
#elseif os(OSX)
|
#elseif os(OSX)
|
||||||
NSWorkspace.sharedWorkspace().openURL(url)
|
NSWorkspace.sharedWorkspace().openURL(url)
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -1240,7 +1240,7 @@ open class Manager : ArmchairManager {
|
|||||||
|
|
||||||
// get the top most controller (= the StoreKit Controller) and dismiss it
|
// get the top most controller (= the StoreKit Controller) and dismiss it
|
||||||
if let presentingController = UIApplication.shared.keyWindow?.rootViewController {
|
if let presentingController = UIApplication.shared.keyWindow?.rootViewController {
|
||||||
if let topController = topMostViewController(presentingController) {
|
if let topController = Manager.topMostViewController(presentingController) {
|
||||||
topController.present(alertView, animated: usesAnimation) { [weak self] _ in
|
topController.present(alertView, animated: usesAnimation) { [weak self] _ in
|
||||||
if let closure = self?.didDisplayAlertClosure {
|
if let closure = self?.didDisplayAlertClosure {
|
||||||
closure()
|
closure()
|
||||||
@@ -1335,7 +1335,7 @@ open class Manager : ArmchairManager {
|
|||||||
|
|
||||||
// get the top most controller (= the StoreKit Controller) and dismiss it
|
// get the top most controller (= the StoreKit Controller) and dismiss it
|
||||||
if let presentingController = UIApplication.shared.keyWindow?.rootViewController {
|
if let presentingController = UIApplication.shared.keyWindow?.rootViewController {
|
||||||
if let topController = topMostViewController(presentingController) {
|
if let topController = Manager.topMostViewController(presentingController) {
|
||||||
topController.dismiss(animated: usesAnimation) {
|
topController.dismiss(animated: usesAnimation) {
|
||||||
if let closure = self.didDismissModalViewClosure {
|
if let closure = self.didDismissModalViewClosure {
|
||||||
closure(usedAnimation)
|
closure(usedAnimation)
|
||||||
@@ -1422,7 +1422,7 @@ open class Manager : ArmchairManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if let rootController = getRootViewController() {
|
if let rootController = Manager.getRootViewController() {
|
||||||
rootController.present(storeViewController, animated: usesAnimation) {
|
rootController.present(storeViewController, animated: usesAnimation) {
|
||||||
self.modalPanelOpen = true
|
self.modalPanelOpen = true
|
||||||
|
|
||||||
@@ -1689,7 +1689,7 @@ open class Manager : ArmchairManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
private func topMostViewController(_ controller: UIViewController?) -> UIViewController? {
|
private static func topMostViewController(_ controller: UIViewController?) -> UIViewController? {
|
||||||
var isPresenting: Bool = false
|
var isPresenting: Bool = false
|
||||||
var topController: UIViewController? = controller
|
var topController: UIViewController? = controller
|
||||||
repeat {
|
repeat {
|
||||||
@@ -1707,7 +1707,7 @@ open class Manager : ArmchairManager {
|
|||||||
return topController
|
return topController
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getRootViewController() -> UIViewController? {
|
private static func getRootViewController() -> UIViewController? {
|
||||||
if var window = UIApplication.shared.keyWindow {
|
if var window = UIApplication.shared.keyWindow {
|
||||||
|
|
||||||
if window.windowLevel != UIWindowLevelNormal {
|
if window.windowLevel != UIWindowLevelNormal {
|
||||||
@@ -1722,20 +1722,30 @@ open class Manager : ArmchairManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for subView in window.subviews {
|
return iterateSubViewsForViewController(window)
|
||||||
if let responder = subView.next {
|
|
||||||
if responder.isKind(of: UIViewController.self) {
|
|
||||||
return topMostViewController(responder as? UIViewController)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func iterateSubViewsForViewController(_ parentView: UIView) -> UIViewController? {
|
||||||
|
for subView in parentView.subviews {
|
||||||
|
if let responder = subView.next {
|
||||||
|
if responder.isKind(of: UIViewController.self) {
|
||||||
|
return topMostViewController(responder as? UIViewController)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let found = iterateSubViewsForViewController(subView) {
|
||||||
|
return found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private func hideRatingAlert() {
|
private func hideRatingAlert() {
|
||||||
if let alert = ratingAlert {
|
if let alert = ratingAlert {
|
||||||
debugLog("Hiding Alert")
|
debugLog("Hiding Alert")
|
||||||
|
|||||||
@@ -194,7 +194,7 @@
|
|||||||
F8111E0419A951050040E7D1 = {
|
F8111E0419A951050040E7D1 = {
|
||||||
CreatedOnToolsVersion = 6.0;
|
CreatedOnToolsVersion = 6.0;
|
||||||
DevelopmentTeam = 9H3S97RP4K;
|
DevelopmentTeam = 9H3S97RP4K;
|
||||||
LastSwiftMigration = 0800;
|
LastSwiftMigration = 0830;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -422,7 +422,7 @@
|
|||||||
PRODUCT_BUNDLE_IDENTIFIER = "com.armchair.$(PRODUCT_NAME:rfc1034identifier)";
|
PRODUCT_BUNDLE_IDENTIFIER = "com.armchair.$(PRODUCT_NAME:rfc1034identifier)";
|
||||||
PRODUCT_NAME = "iOS Example";
|
PRODUCT_NAME = "iOS Example";
|
||||||
PROVISIONING_PROFILE = "";
|
PROVISIONING_PROFILE = "";
|
||||||
SWIFT_VERSION = 2.3;
|
SWIFT_VERSION = 3.0;
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
};
|
};
|
||||||
@@ -440,7 +440,7 @@
|
|||||||
PRODUCT_BUNDLE_IDENTIFIER = "com.armchair.$(PRODUCT_NAME:rfc1034identifier)";
|
PRODUCT_BUNDLE_IDENTIFIER = "com.armchair.$(PRODUCT_NAME:rfc1034identifier)";
|
||||||
PRODUCT_NAME = "iOS Example";
|
PRODUCT_NAME = "iOS Example";
|
||||||
PROVISIONING_PROFILE = "";
|
PROVISIONING_PROFILE = "";
|
||||||
SWIFT_VERSION = 2.3;
|
SWIFT_VERSION = 3.0;
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user