I have seen some answer but not satisfied with them and got some idea, but don't know how to use it properly, so that it will execute in proper way, though i think it should be used in App delegates didFinishLaunching
, but i wanted to be sure before implement it in Live app without any hustle.
SKStoreReviewController
is only work for ios 10.3 what i read, could anybody explain with little bit of code in swift and objective c.
UPDATE:
Actually I'm confused about calling the method requestReview()
, Where do i need to call this method? in rootViewController
's viewDidLoad
or in appDelegate
's didFinishlaunching
?
Thanks.
SKStoreReviewController
is available in iOS 10.3 and later.
According to APPLE's Documents:
You can ask users to rate or review your app while they're using it,
without sending them to the App Store.You determine the points in the
user experience at which it makes sense to call the API and the system
takes care of the rest.
Inorder to display Rate/Review inside the app, you have to add StoreKit
framework.
Please find the Sample code for both language:
Objective C:
#import <StoreKit/StoreKit.h>
- (void)DisplayReviewController {
if([SKStoreReviewController class]){
[SKStoreReviewController requestReview] ;
}
}
since xCode 9 you can do:
#import <StoreKit/StoreKit.h>
- (void)DisplayReviewController {
if (@available(iOS 10.3, *)) {
[SKStoreReviewController requestReview];
}
}
Swift:
import StoreKit
func DisplayReviewController {
if #available( iOS 10.3,*){
SKStoreReviewController.requestReview()
}
}
Update: Ask for a rating only after the user has demonstrated engagement with your app
For Objective C,
1-) Added StoreKit framework from Link Binary With Library
2-) Added framework
#import <StoreKit/StoreKit.h>
3-) Added below code where you want to call App-Review pop-up. In this case, i added in viewDidLoad.
- (void)viewDidLoad {
[super viewDidLoad];
[SKStoreReviewController requestReview];
}
4-) You should be aware of below explain from Apple, When you test in debug mode
When you call this method while your app is still in development mode, a rating/review request view is always displayed so that you can test the user interface and experience. However, this method has no effect when you call it in an app that you distribute using TestFlight.
I think directly calling the below is not an good idea
SKStoreReviewController.requestReview()
It can be done like whenever user open your app the multiple of 10(10,20,30,...100) then you can show for review
so first of all you need to create an file which will be responsible for everything like saving your application open count in userdefaults ,retrieving application open count and showing requestReview()
kindly have a look to the following code snippet
import Foundation
import StoreKit
class SpsRateManager {
private static let instance = SpsRateManager()
var shareinstance: SpsRateManager{
return .instance
}
static func incrementAppOpenedCount() { // called from appdelegate didfinishLaunchingWithOptions:
let userdefault = UserDefaults.standard
let savedvalue = userdefault.integer(forKey: Configuration.APPLICATIONOPENCOUNTSTATUS)
if savedvalue == 0 {
print("Not saved ")
userdefault.set(1, forKey: Configuration.APPLICATIONOPENCOUNTSTATUS)
}
else{
userdefault.set(savedvalue+1, forKey: Configuration.APPLICATIONOPENCOUNTSTATUS)
}
}
static func checkAppopencountandProvideReview(){
let userdefault = UserDefaults.standard
let appopencountvalue = userdefault.integer(forKey: Configuration.APPLICATIONOPENCOUNTSTATUS)
if appopencountvalue % 10 == 0 {
print("its been 10 times so ask for review ")
SpsRateManager().requestReview()
}
else{
print("not enough open count dont show ")
}
}
fileprivate func requestReview() {
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
} else {
// Fallback on earlier versions
// Try any other 3rd party or manual method here.
}
}
}
I think you may implement a method to count when they run the app and store it in UserDefaults, then call requestReview() if the count number is 5 or 10 or something like that (it depends on you), by this way you have more chance of getting a good review.
Adding onto korat's great answer above...
If your supporting a legacy Objective-C app and you want to call DisplayReviewController after a few app opens then do the following:
In your class AppDelegate.m add this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
int count = [[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchCount"];
if(count < 0) count = 0;
[[NSUserDefaults standardUserDefaults] setInteger:count+1 forKey:@"LaunchCount"];
}
//The application was in background and become active
- (void)applicationWillEnterForeground:(UIApplication *)application {
int count = [[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchCount"];
if(count < 0) count = 0;
[[NSUserDefaults standardUserDefaults] setInteger:count+1 forKey:@"LaunchCount"];
}
and in the controller you want to call the function:
- (void)applicationDidBecomeActive {
if ([[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchCount"] == 5) {
[self DisplayReviewController];
}
}