mirror of
https://github.com/UrbanApps/Armchair.git
synced 2026-04-25 02:08:37 +02:00
Update iOS 10.3 review dialog support
This commit is contained in:
committed by
GitHub
parent
dddaa62c25
commit
adc0a0d580
@@ -255,6 +255,14 @@ public func shouldPromptIfRated(_ shouldPromptIfRated: Bool) {
|
|||||||
Manager.defaultManager.shouldPromptIfRated = shouldPromptIfRated
|
Manager.defaultManager.shouldPromptIfRated = shouldPromptIfRated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return whether Armchair will try and present the Storekit review prompt (useful for custom dialog modification)
|
||||||
|
*/
|
||||||
|
public var shouldTryStoreKitReviewPrompt : Bool {
|
||||||
|
return Manager.defaultManager.shouldTryStoreKitReviewPrompt
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If set to true, the main bundle will always be used to load localized strings.
|
* If set to true, the main bundle will always be used to load localized strings.
|
||||||
* Set this to true if you have provided your own custom localizations in
|
* Set this to true if you have provided your own custom localizations in
|
||||||
@@ -1203,22 +1211,46 @@ open class Manager : ArmchairManager {
|
|||||||
return (daysBeforeReminding > 0 && remindButtonTitle != nil)
|
return (daysBeforeReminding > 0 && remindButtonTitle != nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var shouldTryStoreKitReviewPrompt : Bool {
|
||||||
|
if #available(iOS 10.3, *), useStoreKitReviewPrompt { return true }
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func requestStoreKitReviewPrompt() -> Bool {
|
||||||
|
if #available(iOS 10.3, *), useStoreKitReviewPrompt {
|
||||||
|
SKStoreReviewController.requestReview()
|
||||||
|
// Assume this version is rated. There is no API to tell if the user actaully rated.
|
||||||
|
userDefaultsObject?.setBool(true, forKey: keyForArmchairKeyType(ArmchairKey.RatedCurrentVersion))
|
||||||
|
userDefaultsObject?.setBool(true, forKey: keyForArmchairKeyType(ArmchairKey.RatedAnyVersion))
|
||||||
|
userDefaultsObject?.synchronize()
|
||||||
|
|
||||||
|
closeModalPanel()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fileprivate func showRatingAlert() {
|
fileprivate func showRatingAlert() {
|
||||||
if let customClosure = customAlertClosure {
|
if let customClosure = customAlertClosure {
|
||||||
customClosure({[weak self] in self?._rateApp()}, {[weak self] in self?.remindMeLater()}, {[weak self] in self?.dontRate()})
|
customClosure({[weak self] in
|
||||||
|
if let result = self?.requestStoreKitReviewPrompt(), result {
|
||||||
|
///Showed storekit prompt, all done
|
||||||
|
} else {
|
||||||
|
/// Didn't show storekit prompt, present app store manually
|
||||||
|
self?._rateApp()
|
||||||
|
}
|
||||||
|
|
||||||
|
}, {[weak self] in self?.remindMeLater()}, {[weak self] in self?.dontRate()})
|
||||||
if let closure = self.didDisplayAlertClosure {
|
if let closure = self.didDisplayAlertClosure {
|
||||||
closure()
|
closure()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
if #available(iOS 10.3, *), useStoreKitReviewPrompt {
|
if requestStoreKitReviewPrompt() {
|
||||||
SKStoreReviewController.requestReview()
|
///Showed storekit prompt, all done
|
||||||
// Assume this version is rated. There is no API to tell if the user actaully rated.
|
|
||||||
userDefaultsObject?.setBool(true, forKey: keyForArmchairKeyType(ArmchairKey.RatedCurrentVersion))
|
} else {
|
||||||
userDefaultsObject?.setBool(true, forKey: keyForArmchairKeyType(ArmchairKey.RatedAnyVersion))
|
/// Didn't show storekit prompt, present app store manually
|
||||||
userDefaultsObject?.synchronize()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let alertView : UIAlertController = UIAlertController(title: reviewTitle, message: reviewMessage, preferredStyle: UIAlertControllerStyle.alert)
|
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.cancel, handler: {
|
||||||
(alert: UIAlertAction!) in
|
(alert: UIAlertAction!) in
|
||||||
@@ -1248,6 +1280,8 @@ open class Manager : ArmchairManager {
|
|||||||
// note that tint color has to be set after the controller is presented in order to take effect (last checked in iOS 9.3)
|
// note that tint color has to be set after the controller is presented in order to take effect (last checked in iOS 9.3)
|
||||||
alertView.view.tintColor = tintColor
|
alertView.view.tintColor = tintColor
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1294,23 +1328,23 @@ open class Manager : ArmchairManager {
|
|||||||
|
|
||||||
//Close the in-app rating (StoreKit) view and restore the previous status bar style.
|
//Close the in-app rating (StoreKit) view and restore the previous status bar style.
|
||||||
fileprivate func closeModalPanel() {
|
fileprivate func closeModalPanel() {
|
||||||
|
let usedAnimation = usesAnimation
|
||||||
if modalPanelOpen {
|
if modalPanelOpen {
|
||||||
UIApplication.shared.setStatusBarStyle(currentStatusBarStyle, animated:usesAnimation)
|
UIApplication.shared.setStatusBarStyle(currentStatusBarStyle, animated:usesAnimation)
|
||||||
let usedAnimation = usesAnimation
|
|
||||||
modalPanelOpen = false
|
modalPanelOpen = false
|
||||||
|
|
||||||
// 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 = topMostViewController(presentingController) {
|
||||||
topController.dismiss(animated: usesAnimation) {
|
topController.dismiss(animated: usesAnimation) {}
|
||||||
if let closure = self.didDismissModalViewClosure {
|
|
||||||
closure(usedAnimation)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
currentStatusBarStyle = UIStatusBarStyle.default
|
currentStatusBarStyle = UIStatusBarStyle.default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let closure = self.didDismissModalViewClosure {
|
||||||
|
closure(usedAnimation)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elseif os(OSX)
|
#elseif os(OSX)
|
||||||
@@ -1703,23 +1737,19 @@ open class Manager : ArmchairManager {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private func hideRatingAlert() {
|
private func hideRatingAlert() {
|
||||||
|
#if os(OSX)
|
||||||
if let alert = ratingAlert {
|
if let alert = ratingAlert {
|
||||||
debugLog("Hiding Alert")
|
debugLog("Hiding Alert")
|
||||||
#if os(iOS)
|
|
||||||
if alert.isVisible {
|
|
||||||
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 {
|
if let parent = window.sheetParent {
|
||||||
parent.endSheet(window)
|
parent.endSheet(window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
ratingAlert = nil
|
ratingAlert = nil
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func defaultAffiliateCode() -> String {
|
fileprivate func defaultAffiliateCode() -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user