From 2bdd30f9ed3037b775b7a25ad2e2b529957b3dd1 Mon Sep 17 00:00:00 2001 From: Martin Moizard Date: Fri, 1 Sep 2017 09:56:15 +0200 Subject: [PATCH 01/10] Migrate to Swift 3 --- Example/AppDelegate.swift | 2 +- Example/ViewController.swift | 14 +++++++------- iOS Example.xcodeproj/project.pbxproj | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index 435f5a2..52ddb56 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -28,7 +28,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { return true } } diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 7d5703f..2874edc 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -55,12 +55,12 @@ extension ViewController { // Only set it if we are using Armchair localizations 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 - if let developmentLocalization = NSBundle.mainBundle().developmentLocalization { - if currentLocalization != developmentLocalization { + if let developmentLocalization = Bundle.main.developmentLocalization { + if currentLocalization as String != developmentLocalization { 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)" } } @@ -143,7 +143,7 @@ extension ViewController { Armchair.opensInStoreKit(false) // This sets a custom tint color (applies only to UIAlertController). - Armchair.tintColor(UIColor.brownColor()) + Armchair.tintColor(tintColor: UIColor.brown) #endif // This sets the Affiliate code you want to use, but is not required. @@ -216,9 +216,9 @@ extension ViewController { } @IBAction func openUrbanApps(_: AnyObject) { - if let url = NSURL(string: "http://urbanapps.com") { + if let url = URL(string: "http://urbanapps.com") { #if os(iOS) - UIApplication.sharedApplication().openURL(url) + UIApplication.shared.openURL(url) #elseif os(OSX) NSWorkspace.sharedWorkspace().openURL(url) #else diff --git a/iOS Example.xcodeproj/project.pbxproj b/iOS Example.xcodeproj/project.pbxproj index c8cf15d..e724d5b 100644 --- a/iOS Example.xcodeproj/project.pbxproj +++ b/iOS Example.xcodeproj/project.pbxproj @@ -194,7 +194,7 @@ F8111E0419A951050040E7D1 = { CreatedOnToolsVersion = 6.0; DevelopmentTeam = 9H3S97RP4K; - LastSwiftMigration = 0800; + LastSwiftMigration = 0830; }; }; }; @@ -422,7 +422,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.armchair.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "iOS Example"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -440,7 +440,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.armchair.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "iOS Example"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Release; }; From eaebe860da25c8d667d4ca7e61bc1aa995b47604 Mon Sep 17 00:00:00 2001 From: Martin Moizard Date: Fri, 1 Sep 2017 09:56:47 +0200 Subject: [PATCH 02/10] Fix issue when `getRootViewController` would return `nil` --- Source/Armchair.swift | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Source/Armchair.swift b/Source/Armchair.swift index be9d25d..5154deb 100644 --- a/Source/Armchair.swift +++ b/Source/Armchair.swift @@ -1240,7 +1240,7 @@ open class Manager : ArmchairManager { // get the top most controller (= the StoreKit Controller) and dismiss it 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 if let closure = self?.didDisplayAlertClosure { closure() @@ -1335,7 +1335,7 @@ open class Manager : ArmchairManager { // get the top most controller (= the StoreKit Controller) and dismiss it if let presentingController = UIApplication.shared.keyWindow?.rootViewController { - if let topController = topMostViewController(presentingController) { + if let topController = Manager.topMostViewController(presentingController) { topController.dismiss(animated: usesAnimation) { if let closure = self.didDismissModalViewClosure { closure(usedAnimation) @@ -1422,7 +1422,7 @@ open class Manager : ArmchairManager { } - if let rootController = getRootViewController() { + if let rootController = Manager.getRootViewController() { rootController.present(storeViewController, animated: usesAnimation) { self.modalPanelOpen = true @@ -1689,7 +1689,7 @@ open class Manager : ArmchairManager { } #if os(iOS) - private func topMostViewController(_ controller: UIViewController?) -> UIViewController? { + private static func topMostViewController(_ controller: UIViewController?) -> UIViewController? { var isPresenting: Bool = false var topController: UIViewController? = controller repeat { @@ -1707,7 +1707,7 @@ open class Manager : ArmchairManager { return topController } - private func getRootViewController() -> UIViewController? { + private static func getRootViewController() -> UIViewController? { if var window = UIApplication.shared.keyWindow { if window.windowLevel != UIWindowLevelNormal { @@ -1722,20 +1722,30 @@ open class Manager : ArmchairManager { } } - for subView in window.subviews { - if let responder = subView.next { - if responder.isKind(of: UIViewController.self) { - return topMostViewController(responder as? UIViewController) - } - - } - } + return iterateSubViewsForViewController(window) } 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 - + private func hideRatingAlert() { if let alert = ratingAlert { debugLog("Hiding Alert") From 87d68ec2a7af1e83c80f13748db3df36cbf91d4a Mon Sep 17 00:00:00 2001 From: Matt Coneybeare Date: Thu, 14 Sep 2017 19:14:02 -0400 Subject: [PATCH 03/10] Updating podspec --- Armchair.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Armchair.podspec b/Armchair.podspec index d4d6402..4dbf9ef 100644 --- a/Armchair.podspec +++ b/Armchair.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Armchair" - s.version = "0.3.0" + s.version = "0.3.1" s.summary = "A simple yet powerful App Review Manager for iOS and OSX in Swift" s.description = <<-DESC A simple yet powerful App Review Manager for iOS and OSX in Swift. From dfb230dcd2c71060497a13d6ecdb2f505e2c3f62 Mon Sep 17 00:00:00 2001 From: Matt Coneybeare Date: Thu, 14 Sep 2017 20:40:16 -0400 Subject: [PATCH 04/10] Swift 4 and tweaks to example projects --- Armchair.xcodeproj/project.pbxproj | 29 +++++- .../xcshareddata/xcschemes/Armchair.xcscheme | 4 +- .../xcschemes/ArmchairMac.xcscheme | 4 +- Example/AppDelegate.swift | 16 ++-- Example/ViewController.swift | 8 +- Mac Example.xcodeproj/project.pbxproj | 38 ++++---- Source/Armchair.swift | 92 ++++++++++--------- iOS Example.xcodeproj/project.pbxproj | 20 +++- 8 files changed, 128 insertions(+), 83 deletions(-) diff --git a/Armchair.xcodeproj/project.pbxproj b/Armchair.xcodeproj/project.pbxproj index 97bbe9b..84f160c 100644 --- a/Armchair.xcodeproj/project.pbxproj +++ b/Armchair.xcodeproj/project.pbxproj @@ -318,13 +318,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Armchair; TargetAttributes = { E6A0AF6419C9CFF400C3A7DC = { CreatedOnToolsVersion = 6.0; ProvisioningStyle = Manual; }; + E6D8B8EF19C756A4001AD043 = { + LastSwiftMigration = 0900; + }; F8111E3219A95C8B0040E7D1 = { CreatedOnToolsVersion = 6.0; LastSwiftMigration = 0800; @@ -541,7 +544,8 @@ SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -566,7 +570,8 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = ""; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -617,14 +622,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -655,6 +666,7 @@ OTHER_SWIFT_FLAGS = "-DDebug"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -669,14 +681,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -698,6 +716,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -724,7 +743,7 @@ SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -746,7 +765,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = ""; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Armchair.xcodeproj/xcshareddata/xcschemes/Armchair.xcscheme b/Armchair.xcodeproj/xcshareddata/xcschemes/Armchair.xcscheme index 53b90e2..a138fe9 100644 --- a/Armchair.xcodeproj/xcshareddata/xcschemes/Armchair.xcscheme +++ b/Armchair.xcodeproj/xcshareddata/xcschemes/Armchair.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index 52ddb56..c03e5a8 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -28,12 +28,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + AppDelegate.setupArmchair() return true } } - let Pages = "361309726" // Pages iOS + let appID = "361309726" // Pages iOS #elseif os(OSX) @@ -43,9 +44,12 @@ class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var window: NSWindow! + override init() { + AppDelegate.setupArmchair() + } } - let Pages = "409201541" // Pages Mac + let appID = "409201541" // Pages Mac #else #endif @@ -54,10 +58,6 @@ import Armchair extension AppDelegate { - override class func initialize() { - AppDelegate.setupArmchair() - } - class func setupArmchair() { // Normally, all the setup would be here. // But, because we are presenting a few different setups in the example, @@ -68,7 +68,7 @@ extension AppDelegate { // because it needs to receive application life-cycle notifications // // NOTE: The appID call always has to go before any other Armchair calls - Armchair.appID(Pages) + Armchair.appID(appID) Armchair.debugEnabled(true) } } diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 2874edc..4a33272 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -78,7 +78,7 @@ extension ViewController { resetAppReviewManager() // The AppID is the only required setup - Armchair.appID(Pages) + Armchair.appID(appID) // Debug means that it will popup on the next available change Armchair.debugEnabled(true) @@ -96,7 +96,7 @@ extension ViewController { resetAppReviewManager() // The AppID is the only required setup - Armchair.appID(Pages) + Armchair.appID(appID) // Debug means that it will popup on the next available change Armchair.debugEnabled(true) @@ -193,7 +193,7 @@ extension ViewController { resetAppReviewManager() // The AppID is the only required setup - Armchair.appID(Pages) + Armchair.appID(appID) // Debug means that it will popup on the next available change Armchair.debugEnabled(true) @@ -220,7 +220,7 @@ extension ViewController { #if os(iOS) UIApplication.shared.openURL(url) #elseif os(OSX) - NSWorkspace.sharedWorkspace().openURL(url) + NSWorkspace.shared.open(url) #else #endif } diff --git a/Mac Example.xcodeproj/project.pbxproj b/Mac Example.xcodeproj/project.pbxproj index db29f24..c70f4c0 100644 --- a/Mac Example.xcodeproj/project.pbxproj +++ b/Mac Example.xcodeproj/project.pbxproj @@ -33,13 +33,6 @@ remoteGlobalIDString = E6D8B8F919C756A4001AD043; remoteInfo = ArmchairMac; }; - E60FA80119C90D3500179D70 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = E60FA7F719C90D3500179D70 /* Armchair.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = E6D8B92819C880A9001AD043; - remoteInfo = ArmchairTests; - }; E60FA80319C90D7100179D70 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = E60FA7F719C90D3500179D70 /* Armchair.xcodeproj */; @@ -135,7 +128,6 @@ E60FA80019C90D3500179D70 /* Armchair.framework */, E6F6156919C9FE8900C0B51C /* Armchair.bundle */, E6F6159819CA003600C0B51C /* Armchair.bundle */, - E60FA80219C90D3500179D70 /* ArmchairTests.xctest */, ); name = Products; sourceTree = ""; @@ -169,7 +161,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Armchair; TargetAttributes = { E60FA7B919C908FE00179D70 = { @@ -216,13 +208,6 @@ remoteRef = E60FA7FF19C90D3500179D70 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - E60FA80219C90D3500179D70 /* ArmchairTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = ArmchairTests.xctest; - remoteRef = E60FA80119C90D3500179D70 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; E6F6156919C9FE8900C0B51C /* Armchair.bundle */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; @@ -300,13 +285,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -315,6 +308,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -332,6 +326,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -343,13 +338,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; @@ -358,6 +361,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -367,6 +371,8 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Source/Armchair.swift b/Source/Armchair.swift index 5154deb..5a593e4 100644 --- a/Source/Armchair.swift +++ b/Source/Armchair.swift @@ -69,18 +69,6 @@ public func reviewTitle(_ reviewTitle: String) { Manager.defaultManager.reviewTitle = reviewTitle } -/* - * If set to true, use SKStoreReviewController's requestReview() prompt instead of the default prompt. - * If not on iOS 10.3+, reort to the default prompt. - * Default => false. - */ -public func useStoreKitReviewPrompt() -> Bool { - return Manager.defaultManager.useStoreKitReviewPrompt -} -public func useStoreKitReviewPrompt(_ useStoreKitReviewPrompt: Bool) { - Manager.defaultManager.useStoreKitReviewPrompt = useStoreKitReviewPrompt -} - /* * Get/Set the message to use on the review prompt. * Default value is a localized @@ -292,6 +280,20 @@ public func affiliateCampaignCode(_ affiliateCampaignCode: String) { Manager.defaultManager.affiliateCampaignCode = affiliateCampaignCode } +#if os(iOS) + /* + * If set to true, use SKStoreReviewController's requestReview() prompt instead of the default prompt. + * If not on iOS 10.3+, reort to the default prompt. + * Default => false. + */ + public func useStoreKitReviewPrompt() -> Bool { + return Manager.defaultManager.useStoreKitReviewPrompt + } + public func useStoreKitReviewPrompt(_ useStoreKitReviewPrompt: Bool) { + Manager.defaultManager.useStoreKitReviewPrompt = useStoreKitReviewPrompt + } +#endif + /* * 'true' will show the Armchair alert everytime. Useful for testing * how your message looks and making sure the link to your app's review page works. @@ -1241,7 +1243,7 @@ open class Manager : ArmchairManager { // get the top most controller (= the StoreKit Controller) and dismiss it if let presentingController = UIApplication.shared.keyWindow?.rootViewController { 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 { closure() } @@ -1284,14 +1286,14 @@ open class Manager : ArmchairManager { alert.addButton(withTitle: cancelButtonTitle) ratingAlert = alert - if let window = NSApplication.shared().keyWindow { + if let window = NSApplication.shared.keyWindow { alert.beginSheetModal(for: window) { - (response: NSModalResponse) in - self.handleNSAlert(returnCode: response) + (response: NSApplication.ModalResponse) in + self.handleNSAlertResponse(response) } } else { - let returnCode = alert.runModal() - handleNSAlert(returnCode:returnCode) + let response = alert.runModal() + handleNSAlertResponse(response) } if let closure = self.didDisplayAlertClosure { @@ -1349,24 +1351,24 @@ open class Manager : ArmchairManager { #elseif os(OSX) - private func handleNSAlert(returnCode: NSInteger) { - switch (returnCode) { - case NSAlertFirstButtonReturn: - // they want to rate it - _rateApp() - case NSAlertSecondButtonReturn: - // remind them later or cancel - if showsRemindButton() { - remindMeLater() - } else { - dontRate() - } - case NSAlertThirdButtonReturn: - // they don't want to rate it - dontRate() + private func handleNSAlertResponse(_ response: NSApplication.ModalResponse) { + switch (response) { + case .alertFirstButtonReturn: + // they want to rate it + _rateApp() + case .alertSecondButtonReturn: + // remind them later or cancel + if showsRemindButton() { + remindMeLater() + } else { + dontRate() + } + case .alertThirdButtonReturn: + // they don't want to rate it + dontRate() default: - return - } + return + } } #else @@ -1449,7 +1451,7 @@ open class Manager : ArmchairManager { #elseif os(OSX) if let url = URL(string: reviewURLString()) { - let opened = NSWorkspace.shared().open(url) + let opened = NSWorkspace.shared.open(url) if !opened { debugLog("Failed to open \(url)") } @@ -1754,7 +1756,7 @@ open class Manager : ArmchairManager { alert.dismiss(withClickedButtonIndex: alert.cancelButtonIndex, animated: false) } #elseif os(OSX) - if let window = NSApplication.shared().keyWindow { + if let window = NSApplication.shared.keyWindow { if let parent = window.sheetParent { parent.endSheet(window) } @@ -1777,12 +1779,12 @@ open class Manager : ArmchairManager { // MARK: - // MARK: Notification Handlers - public func appWillResignActive(_ notification: Notification) { + @objc public func appWillResignActive(_ notification: Notification) { debugLog("appWillResignActive:") hideRatingAlert() } - public func applicationDidFinishLaunching(_ notification: Notification) { + @objc public func applicationDidFinishLaunching(_ notification: Notification) { DispatchQueue.global(qos: .background).async { self.debugLog("applicationDidFinishLaunching:") self.migrateKeysIfNecessary() @@ -1790,7 +1792,7 @@ open class Manager : ArmchairManager { } } - public func applicationWillEnterForeground(_ notification: Notification) { + @objc public func applicationWillEnterForeground(_ notification: Notification) { DispatchQueue.global(qos: .background).async { self.debugLog("applicationWillEnterForeground:") self.migrateKeysIfNecessary() @@ -1818,12 +1820,12 @@ open class Manager : ArmchairManager { fileprivate func setupNotifications() { #if os(iOS) NotificationCenter.default.addObserver(self, selector: #selector(Manager.appWillResignActive(_:)), name: NSNotification.Name.UIApplicationWillResignActive, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(UIApplicationDelegate.applicationDidFinishLaunching(_:)), name: NSNotification.Name.UIApplicationDidFinishLaunching, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(UIApplicationDelegate.applicationWillEnterForeground(_:)), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(Manager.applicationDidFinishLaunching(_:)), name: NSNotification.Name.UIApplicationDidFinishLaunching, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(Manager.applicationWillEnterForeground(_:)), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil) #elseif os(OSX) - NotificationCenter.default.addObserver(self, selector: #selector(Manager.appWillResignActive(_:)), name: NSNotification.Name.NSApplicationWillResignActive, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(NSApplicationDelegate.applicationDidFinishLaunching(_:)), name: NSNotification.Name.NSApplicationDidFinishLaunching, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(Manager.applicationWillEnterForeground(_:)), name: NSNotification.Name.NSApplicationWillBecomeActive, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(Manager.appWillResignActive(_:)), name: NSApplication.willResignActiveNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(Manager.applicationDidFinishLaunching(_:)), name: NSApplication.didFinishLaunchingNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(Manager.applicationWillEnterForeground(_:)), name: NSApplication.willBecomeActiveNotification, object: nil) #else #endif diff --git a/iOS Example.xcodeproj/project.pbxproj b/iOS Example.xcodeproj/project.pbxproj index e724d5b..1d4c1c7 100644 --- a/iOS Example.xcodeproj/project.pbxproj +++ b/iOS Example.xcodeproj/project.pbxproj @@ -188,7 +188,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Armchair; TargetAttributes = { F8111E0419A951050040E7D1 = { @@ -327,14 +327,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -362,6 +368,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -374,14 +381,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -401,6 +414,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -422,7 +436,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.armchair.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "iOS Example"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -440,7 +454,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.armchair.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "iOS Example"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; From a4f97f92c3e3df09cc45e5b3c34d5cef712fda9b Mon Sep 17 00:00:00 2001 From: Matt Coneybeare Date: Fri, 15 Sep 2017 09:20:14 -0400 Subject: [PATCH 05/10] updated podspec --- Armchair.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Armchair.podspec b/Armchair.podspec index 4dbf9ef..64d5c1b 100644 --- a/Armchair.podspec +++ b/Armchair.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Armchair" - s.version = "0.3.1" + s.version = "0.3.2" s.summary = "A simple yet powerful App Review Manager for iOS and OSX in Swift" s.description = <<-DESC A simple yet powerful App Review Manager for iOS and OSX in Swift. From 04cb290dc194675cd47c5a375c55d30555e97316 Mon Sep 17 00:00:00 2001 From: Matt Coneybeare Date: Sun, 17 Sep 2017 08:23:23 -0400 Subject: [PATCH 06/10] updated podspec --- Armchair.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Armchair.podspec b/Armchair.podspec index 64d5c1b..1198e0f 100644 --- a/Armchair.podspec +++ b/Armchair.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Armchair" - s.version = "0.3.2" + s.version = "0.3.3" s.summary = "A simple yet powerful App Review Manager for iOS and OSX in Swift" s.description = <<-DESC A simple yet powerful App Review Manager for iOS and OSX in Swift. From 5c963bda6a8a3e5ed28eb789c88dbee2c5a318d2 Mon Sep 17 00:00:00 2001 From: ArturoLee Date: Mon, 2 Oct 2017 19:41:34 -0400 Subject: [PATCH 07/10] =?UTF-8?q?UIAlertActionStyle.cancel=20was=20assigne?= =?UTF-8?q?d=20to=20the=20rate=20button=20so=20it=20can=20appear=20bold.?= =?UTF-8?q?=E2=80=A9UIAlertActionStyle.default=20was=20assigned=20to=20the?= =?UTF-8?q?=20cancel=20button=20so=20it=20can=20have=20a=20regular=20font?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Armchair.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Armchair.swift b/Source/Armchair.swift index 5a593e4..4a4a4e2 100644 --- a/Source/Armchair.swift +++ b/Source/Armchair.swift @@ -1225,7 +1225,7 @@ open class Manager : ArmchairManager { if (operatingSystemVersion >= 8 && usesAlertController) || operatingSystemVersion >= 9 { /* iOS 8 uses new UIAlertController API*/ let alertView : UIAlertController = UIAlertController(title: reviewTitle, message: reviewMessage, preferredStyle: UIAlertControllerStyle.alert) - alertView.addAction(UIAlertAction(title: cancelButtonTitle, style:UIAlertActionStyle.cancel, handler: { + alertView.addAction(UIAlertAction(title: cancelButtonTitle, style:UIAlertActionStyle.default, handler: { (alert: UIAlertAction!) in self.dontRate() })) @@ -1235,7 +1235,7 @@ open class Manager : ArmchairManager { self.remindMeLater() })) } - alertView.addAction(UIAlertAction(title: rateButtonTitle, style:UIAlertActionStyle.default, handler: { + alertView.addAction(UIAlertAction(title: rateButtonTitle, style:UIAlertActionStyle.cancel, handler: { (alert: UIAlertAction!) in self._rateApp() })) From 74ae4516308b1c2dd0a8d3171503fa4579c83501 Mon Sep 17 00:00:00 2001 From: Matt Coneybeare Date: Wed, 11 Oct 2017 11:46:01 -0400 Subject: [PATCH 08/10] updated iOS 11 review string template --- .swift-version | 2 +- Armchair.podspec | 2 +- Source/Armchair.swift | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.swift-version b/.swift-version index 9f55b2c..5186d07 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +4.0 diff --git a/Armchair.podspec b/Armchair.podspec index 1198e0f..03420d5 100644 --- a/Armchair.podspec +++ b/Armchair.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Armchair" - s.version = "0.3.3" + s.version = "0.3.4" s.summary = "A simple yet powerful App Review Manager for iOS and OSX in Swift" s.description = <<-DESC A simple yet powerful App Review Manager for iOS and OSX in Swift. diff --git a/Source/Armchair.swift b/Source/Armchair.swift index 4a4a4e2..6e30a8a 100644 --- a/Source/Armchair.swift +++ b/Source/Armchair.swift @@ -763,7 +763,8 @@ open class Manager : ArmchairManager { #if os(iOS) fileprivate var ratingAlert: UIAlertView? = nil - fileprivate let reviewURLTemplate = "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&id=APP_ID&at=AFFILIATE_CODE&ct=AFFILIATE_CAMPAIGN_CODE&action=write-review" + fileprivate let reviewURLTemplate = "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&id=APP_ID&at=AFFILIATE_CODE&ct=AFFILIATE_CAMPAIGN_CODE&action=write-review" + fileprivate let reviewURLTemplateiOS11 = "https://itunes.apple.com/us/app/idAPP_ID?ls=1&mt=8&at=AFFILIATE_CODE&ct=AFFILIATE_CAMPAIGN_CODE&action=write-review" #elseif os(OSX) private var ratingAlert: NSAlert? = nil private let reviewURLTemplate = "macappstore://itunes.apple.com/us/app/idAPP_ID?ls=1&mt=12&at=AFFILIATE_CODE&ct=AFFILIATE_CAMPAIGN_CODE" @@ -1462,7 +1463,7 @@ open class Manager : ArmchairManager { } fileprivate func reviewURLString() -> String { - let template = reviewURLTemplate + let template = operatingSystemVersion >= 11 ? reviewURLTemplateiOS11 : reviewURLTemplate var reviewURL = template.replacingOccurrences(of: "APP_ID", with: "\(appID)") reviewURL = reviewURL.replacingOccurrences(of: "AFFILIATE_CODE", with: "\(affiliateCode)") reviewURL = reviewURL.replacingOccurrences(of: "AFFILIATE_CAMPAIGN_CODE", with: "\(affiliateCampaignCode)") From 86bb26031df92fb6cd8ba71a530066b3ba543065 Mon Sep 17 00:00:00 2001 From: Matt Coneybeare Date: Wed, 11 Oct 2017 12:54:42 -0400 Subject: [PATCH 09/10] updated iOS 11 review string template --- Source/Armchair.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Armchair.swift b/Source/Armchair.swift index 6e30a8a..a62368c 100644 --- a/Source/Armchair.swift +++ b/Source/Armchair.swift @@ -1463,7 +1463,12 @@ open class Manager : ArmchairManager { } fileprivate func reviewURLString() -> String { - let template = operatingSystemVersion >= 11 ? reviewURLTemplateiOS11 : reviewURLTemplate + #if os(iOS) + let template = operatingSystemVersion >= 11 ? reviewURLTemplateiOS11 : reviewURLTemplate + #elseif os(OSX) + let template = reviewURLTemplate + #else + #endif var reviewURL = template.replacingOccurrences(of: "APP_ID", with: "\(appID)") reviewURL = reviewURL.replacingOccurrences(of: "AFFILIATE_CODE", with: "\(affiliateCode)") reviewURL = reviewURL.replacingOccurrences(of: "AFFILIATE_CAMPAIGN_CODE", with: "\(affiliateCampaignCode)") From 804141486dff5a98e0c2a4b13983bbf4d75bee82 Mon Sep 17 00:00:00 2001 From: Matt Coneybeare Date: Wed, 11 Oct 2017 14:28:33 -0400 Subject: [PATCH 10/10] update podspec --- Armchair.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Armchair.podspec b/Armchair.podspec index 03420d5..e0c0f1e 100644 --- a/Armchair.podspec +++ b/Armchair.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Armchair" - s.version = "0.3.4" + s.version = "0.3.5" s.summary = "A simple yet powerful App Review Manager for iOS and OSX in Swift" s.description = <<-DESC A simple yet powerful App Review Manager for iOS and OSX in Swift.