mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
#1365 (in-app ratings dialog)
This commit is contained in:
parent
db114dc403
commit
1367628a9a
1 changed files with 64 additions and 0 deletions
|
@ -7,9 +7,51 @@
|
|||
//
|
||||
|
||||
import UIKit
|
||||
import StoreKit
|
||||
|
||||
///Sidebar listing all of the feeds.
|
||||
class FeedsViewController: FeedsObjCViewController {
|
||||
struct Keys {
|
||||
static let reviewDate = "datePromptedForReview"
|
||||
static let reviewVersion = "versionPromptedForReview"
|
||||
}
|
||||
|
||||
var appearCount = 0
|
||||
|
||||
lazy var appVersion: String = {
|
||||
let infoDictionaryKey = kCFBundleVersionKey as String
|
||||
|
||||
guard let currentVersion = Bundle.main.object(forInfoDictionaryKey: infoDictionaryKey) as? String else {
|
||||
fatalError("Expected to find a bundle version in the info dictionary")
|
||||
}
|
||||
|
||||
return currentVersion
|
||||
}()
|
||||
|
||||
var datePromptedForReview: Date {
|
||||
get {
|
||||
guard let date = UserDefaults.standard.object(forKey: Keys.reviewDate) as? Date else {
|
||||
let date = Date()
|
||||
UserDefaults.standard.set(date, forKey: Keys.reviewDate)
|
||||
return date
|
||||
}
|
||||
|
||||
return date
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: Keys.reviewDate)
|
||||
}
|
||||
}
|
||||
|
||||
var versionPromptedForReview: String {
|
||||
get {
|
||||
return UserDefaults.standard.string(forKey: Keys.reviewVersion) ?? ""
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: Keys.reviewVersion)
|
||||
}
|
||||
}
|
||||
|
||||
var loadWorkItem: DispatchWorkItem?
|
||||
|
||||
@objc func loadNotificationStory() {
|
||||
|
@ -26,4 +68,26 @@ class FeedsViewController: FeedsObjCViewController {
|
|||
loadWorkItem = workItem
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + (isOffline ? .seconds(1) : .milliseconds(100)), execute: workItem)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
appearCount += 1
|
||||
|
||||
let month: TimeInterval = 60 * 60 * 24 * 30
|
||||
let promptedDate = datePromptedForReview
|
||||
let currentVersion = appVersion
|
||||
let promptedVersion = versionPromptedForReview
|
||||
|
||||
// We only get a few prompts per year, so only ask for a review if gone back to the Feeds list several times, it's been at least a month since the last prompt, and it's a different version.
|
||||
if appearCount >= 5, -promptedDate.timeIntervalSinceNow > month, currentVersion != promptedVersion, let scene = view.window?.windowScene {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { [navigationController] in
|
||||
if navigationController?.topViewController is FeedsViewController {
|
||||
SKStoreReviewController.requestReview(in: scene)
|
||||
self.datePromptedForReview = Date()
|
||||
self.versionPromptedForReview = currentVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue