swift - SKStoreReviewController API 是否也适用于 MacOS?如果是,如何实现?

标签 swift macos

我在我的 iOS 应用程序中使用 SKStoreReviewController API 来获取我的应用程序的评论。我也想将其实现到我的 MacOS 应用程序中,但似乎这是不可能的。我导入了 StoreKit,但它显示“使用未解析的标识符‘SKStoreReviewController’”。我是否需要以不同的方式实现这一点,或者这不适合用于 Mac Appstore?

最佳答案

正如 Marek 指出的,SKStoreReviewController 类自 macOS 10.14+ 起可用。

Use the requestReview() method to indicate when it makes sense within the logic of your app to ask the user for ratings and reviews within your app.

苹果仍然在 Human Interface Guidelines 中推荐不使用按钮或其他控件来请求反馈和触发,而仅在其他情况下触发。

Apple 有一个不错的 example code处理仅针对特定操作显示的评论:

// If the count has not yet been stored, this will return 0
var count = UserDefaults.standard.integer(forKey: UserDefaultsKeys.processCompletedCountKey)
count += 1
UserDefaults.standard.set(count, forKey: UserDefaultsKeys.processCompletedCountKey)

print("Process completed \(count) time(s)")

// Get the current bundle version for the app
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") }

let lastVersionPromptedForReview = UserDefaults.standard.string(forKey: UserDefaultsKeys.lastVersionPromptedForReviewKey)

// Has the process been completed several times and the user has not already been prompted for this version?
if count >= 4 && currentVersion != lastVersionPromptedForReview {
    let twoSecondsFromNow = DispatchTime.now() + 2.0
    DispatchQueue.main.asyncAfter(deadline: twoSecondsFromNow, execute: { 
        SKStoreReviewController.requestReview()
        UserDefaults.standard.set(currentVersion, forKey: UserDefaultsKeys.lastVersionPromptedForReviewKey)
    })
}

即使当我只调用 SKStoreReviewController.requestReview() 时,也没有出现审核提示。有谁知道 macOS 的具体技巧吗?

编辑:我已向应用商店提交了更新,并且审核提示正在运行!我不知道为什么它在测试时没有出现,但在生产中它似乎可以工作!

关于swift - SKStoreReviewController API 是否也适用于 MacOS?如果是,如何实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46604086/

相关文章:

swift - CIFilter CISmoothLinearGradient 在 Swift 中传递颜色时崩溃

ios - Swift 3 - 将 bool 值发送到不同的类

python - 如何确定文件是否为只读

swift - 将 UI BarButtonSystemItem 图标添加到 Nav-Toolbar (SWIFT)

ios - 在 swift IOS 中使代码更有条理

swift - 在 Swift 3 中,这个实例中 self 指的是什么对象

xcode - OSX 菜单栏应用程序在存档和导出时未启动,如何调试?

在没有 XCode 的情况下使用 CGL/NSOpenGL 在 OSX 上使用 OpenGL 的 C++ 代码?

Android 模拟器 Mac OSX 位置

mysql - 当我尝试通过 http ://localhost/xampp homepage 使用它时,phpmyadmin 拒绝我访问