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

6

23

I've read about this new feature available in iOS 10.3 and thought it will be more flexible and out of the box. But after I read the docs I found out that you need to decide the time to show it and the viewController who calls it. Is there any way I can make it trigger after a random period of time in any viewController is showing at that moment?

Ezekielezell answered 28/3, 2017 at 16:55 Comment(2)
Look at the this. https://mcmap.net/q/363930/-skstore-review-controller-how-to-use-it-in-a-correct-wayHemorrhage
Showing the review dialog at a random time probably is not a good idea according to the Apple guideline: Don’t interrupt the user, especially when they’re performing a time-sensitive or stressful task.Epsilon
S
27

In your AppDelegate:

Swift:

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

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.

Sanderling answered 29/3, 2017 at 16:43 Comment(2)
Does Apple know not to ask if the current user has submitted a review on the current version?Intelligence
@MichaelReilly yes they doAstigmatism
G
14

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.

Geophilous answered 31/3, 2017 at 6:40 Comment(4)
And (for others who get build errors)... be sure to Link Binary "StoreKit.framework".Stream
@Ezekielezell actually I still need to check if the systemVersion is greater than 10.2 so that I may fall back to my custom rating request.Neoma
@zakaria For versions prior to 10.2, won't referencing a class name that is completely unknown to an operating system built before the class was created, crash the operating system?Blowing
@WoJo I checked it on iOS 9 and it doesn't crash. Seems like StoreKit framework newest version is part of the app you build.Westphalia
P
9

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.

Photogene answered 27/4, 2017 at 14:20 Comment(0)
J
7

Taking Peter Johnson's advice, I created a simple class where you can just stick the method in at the desired spot in your code and it'll pop up at a spot where the user's just had a success.

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

To use it, stick this where you want it to be called and hopefully you won't tick off users with randomness.

ReviewUtility.sharedInstance.recordLaunch()
Jueta answered 3/10, 2017 at 2:28 Comment(0)
E
5

Showing the dialog at random time is not probably a good idea. Please see the Apple guideline which mentions: Don’t interrupt the user, especially when they’re performing a time-sensitive or stressful task.

This is what Apple suggests:

Ask for a rating only after the user has demonstrated engagement with your app. For example, prompt the user upon the completion of a game level or productivity task. Never ask for a rating on first launch or during onboarding. Allow ample time to form an opinion.

Don’t be a pest. Repeated rating prompts can be irritating, and may even negatively influence the user’s opinion of your app. Allow at least a week or two between rating requests and only prompt again after the user has demonstrated additional engagement with your app.

This post is also quite interesting...

Epsilon answered 26/3, 2018 at 23:1 Comment(0)
S
1

I cant add comments yet but if you are using Appirater you might want to check the version to see if its lower than 10.3 so the other Appirater review message box pops up.

Suppress answered 28/5, 2017 at 19:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.