如何使用requestReview(SKStore Review Controller)在一段随机时间后在当前viewController中显示查看弹出窗口

Zak*_*ria 22 objective-c storekit ios

我已经阅读了iOS 10.3中提供的这一新功能,并认为它将更灵活,开箱即用.但是在我阅读了文档后,我发现你需要决定显示它的时间和调用它的viewController.有没有什么方法可以让我在任何一个viewController在那一刻显示的随机时间后触发它?

Mic*_*cks 26

在你的AppDelegate中:

迅速:

import StoreKit

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let shortestTime: UInt32 = 50
    let longestTime: UInt32 = 500
    guard let timeInterval = TimeInterval(exactly: arc4random_uniform(longestTime - shortestTime) + shortestTime) else { return true }

    Timer.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(AppDelegate.requestReview), userInfo: nil, repeats: false)

}

@objc func requestReview() {
    SKStoreReviewController.requestReview()
}
Run Code Online (Sandbox Code Playgroud)

Objective-C的:

#import <StoreKit/StoreKit.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    int shortestTime = 50;
    int longestTime = 500;
    int timeInterval = arc4random_uniform(longestTime - shortestTime) + shortestTime;

    [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(requestReview) userInfo:nil repeats:NO];
}

- (void)requestReview {
    [SKStoreReviewController requestReview];
}
Run Code Online (Sandbox Code Playgroud)

上面的代码将要求Apple提示用户在应用程序完成启动后的50到500秒之间的随机时间对应用程序进行评级.请记住,根据Apple的文档,无法保证在调用requestReview时会显示评级提示.


Omk*_*hav 13

对于Objective - C:

添加StoreKit.framework

然后在你的viewController.h中

#import <StoreKit/StoreKit.h>
Run Code Online (Sandbox Code Playgroud)

然后在你的函数调用中:

            [SKStoreReviewController requestReview];
Run Code Online (Sandbox Code Playgroud)

对于斯威夫特

添加StoreKit.framework

在您的ViewController.swift中

import StoreKit
Run Code Online (Sandbox Code Playgroud)

然后在你的函数调用中:

SKStoreReviewController.requestReview()
Run Code Online (Sandbox Code Playgroud)

而已 !Apple会在何时显示评级(随机).在开发中,每次调用它时都会调用它.

编辑:无需检查操作系统版本,如果操作系统小于10.3,StoreKit将不会弹出,感谢Zakaria.


Pet*_*son 9

随机突然出现并不是一种使用该例程的好方法,并且不仅违反了Apple的建议,而且会给你带来不那么好的结果.

在随机时间弹出用户使用户不会像在适当的时候提示他们那样成功 - 例如当他们刚刚完成一个级别或创建一个文档时,并且具有那种温暖模糊的成就感.


Adr*_*ian 7

根据彼得约翰逊的建议,我创建了一个简单的类,您可以将该方法放在代码中的所需位置,它将弹出一个用户刚刚成功的位置.

struct DefaultKeys {
  static let uses = "uses"
}


class ReviewUtility {

  //  Default Keys stored in Structs.swift

  static let sharedInstance = ReviewUtility()

  private init() {}

  func recordLaunch() {
    let defaults = UserDefaults.standard

    // if there's no value set when the app launches, create one
    guard defaults.value(forKey: DefaultKeys.uses) != nil else { defaults.set(1, forKey: DefaultKeys.uses); return }
    // read the value
    var totalLaunches: Int = defaults.value(forKey: DefaultKeys.uses) as! Int
    // increment it
    totalLaunches += 1
    // write the new value
    UserDefaults.standard.set(totalLaunches, forKey: DefaultKeys.uses)

    // pick whatever interval you want
    if totalLaunches % 20 == 0 {
      // not sure if necessary, but being neurotic
      if #available(iOS 10.3, *) {
        // do storekit review here
        SKStoreReviewController.requestReview()
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

要使用它,请将其粘贴到您希望它被调用的位置,并希望您不会随机选择用户.

ReviewUtility.sharedInstance.recordLaunch()
Run Code Online (Sandbox Code Playgroud)


pet*_*syn 5

随机显示对话框可能不是一个好主意.请参阅提及的Apple指南:不要打断用户,特别是当他们执行时间敏感或压力很大的任务时.

这就是Apple的建议:

仅在用户证明与您的应用互动后才要求评分.例如,在完成游戏级别生产力任务时提示用户.永远不要在首次发布或入职时要求评级.留出足够的时间来形成意见.

不要害虫.重复的评级提示可能会令人恼火,甚至可能会对用户对您的应用的看法产生负面影响.允许至少一个星期或两个等级之间的请求和用户展示了额外的接合与您的应用程序后,方可再次提示.

这篇文章也很有意思......