app内评价 SKStoreReviewController

SKStoreReviewController

/** Request StoreKit to ask the user for an app review. This may or may not show any UI.
 *
 *  Given this may not succussfully present an alert to the user, it is not appropriate for use
 *  from a button or any other user action. For presenting a write review form, a deep link is 
 *  available to the App Store by appending the query params "action=write-review" to a product URL.
 */


if (@available(iOS 10.3, *)) {
    #import <StoreKit/SKStoreReviewController.h>
    [SKStoreReviewController requestReview];
}

note:

  1. 即使调用 requestReview, 也不一定会出现UI
  2. 测试环境不能点提交按钮
  3. 只能评星, 不能提交评论内容
  4. 数量不限制, 但不要过于频繁, 官方建议每个版本提示一次
  5. 如果写评论内容:可以在openURL后面拼接 action=write-review, 可以直接跳转到App Store评论页
  6. 官方文档

Sample 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) { [navigationController] in
        if navigationController?.topViewController is ProcessCompletedViewController {
            SKStoreReviewController.requestReview()
            UserDefaults.standard.set(currentVersion, forKey: UserDefaultsKeys.lastVersionPromptedForReviewKey)
        }
    }
}

你可能感兴趣的:(ios平台)