How to use requestReview (SKStore Review Controller) to show review popup in the current viewController after a random period of time How to use requestReview (SKStore Review Controller) to show review popup in the current viewController after a random period of time ios ios

How to use requestReview (SKStore Review Controller) to show review popup in the current viewController after a random period of time


In your AppDelegate:

Swift:

import StoreKitfunc 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()}

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];}

The code above will ask Apple to prompt the user to rate the app at a random time between 50 and 500 seconds after the app finishes launching.Remember that according to Apple's docs, there is no guarantee that the rating prompt will be presented when the requestReview is called.


For Objective - C:

Add StoreKit.framework

Then in your viewController.h

#import <StoreKit/StoreKit.h>

Then in your function call :

            [SKStoreReviewController requestReview];

For Swift

Add StoreKit.framework

In your ViewController.swift

import StoreKit

Then in your function call :

       if #available(iOS 10.3, *) {            SKStoreReviewController.requestReview()        } else {            // Open App Store with OpenURL method        }

That's it ! Apple will take care of when it would show the rating (randomly).When in development it will get called every time you call it.

Edited : No need to check OS version, StoreKit won't popup if the OS is less than 10.3, thank Zakaria.


Popping up at a random time is not a good way to use that routine, and is not only in contravention of Apple's advice, but will give you less-than-great results.

Annoying the user with a pop up at a random time will never be as successful as prompting them at an appropriate time- such as when they have just completed a level or created a document, and have that warm fuzzy feeling of achievement.