Step by Step Swift Tutorial: Proper way to request review using SKStoreReviewController in iOS 10.3 and higher by b2travel

View this thread on steempeak.com
· @b2travel · (edited)
$0.18
Step by Step Swift Tutorial: Proper way to request review using SKStoreReviewController in iOS 10.3 and higher
![1491598043191.png](https://steemitimages.com/DQmZ4v19WroKV2t1qhgPZTEszwsScMH2ZJZukg2Vsr3RrLb/1491598043191.png)

One of the major targets of app developers is to get better exposure to the community and receive feedback from users to improve the apps and also encourage others to use their apps. For years, developers were using third party methods to suggest receiving review from users which mostly were based on how long and how often the user is engaged with their app. But one major issue in using those 3rd party methods was that the experience was not as seamless as you would expect. Usually, the user was sent out of the app to AppStore app to write the review where they even had to choose Review tab and then start writing the review. 

In iOS 10.3 update, Apple made several major changes in the iOS platform, in which one of the most favorable ones for developers is an official method for asking for review from users. From iOS 10.3, now we can ask StoreKit to ask user for their review and it would handle the rest of the work. You can see the documentations here. Theoretically, the developer only needs to add one line of code to request for review but there are couple notes to consider. 

---
Based on the documentations, the request review function uses a proprietary method to analyze if it is a suitable time to ask user for a review, therefore it is strongly recommended that developers avoid calling this function in response to a user action. For example, if you put request review in callback function for touching a button, iOS might decide not to show anything at the moment, so the user might think your app is not functioning well. On the other hand, it is important to consider not asking for user input very early, possibly wait for couple runs and then ask for review. Although we do not know what are Apple’s algorithms, but until we get to know how the method behaves, the best integration approach is to make sure we ask user at a proper time. 

> **Note**: during development, all request for reviews would be accepted. meaning every single time, a request for review dialog would appear on screen but you are not able to submit the review. In Testflight, none of the requests will be approved, so do not panic if review dialog does not show up in your Testflight sessions. Once the app goes to production, it would use the Apple’s methods to show the dialog whenever it is suitable.

Without further ado, here is how you can implement the request for review in Swift.

1- First, you need to import StoreKit

```Swift
import StoreKit

```
2- Now you can ask for review by

```Swift
SKStoreReviewController.requestReview()

```

**That's it!** Much easier as you might have imagined! 

Although if you would like to support older iOS versions it is better to do so like the following:

```
if #available(iOS 10.3, *) {
    SKStoreReviewController.requestReview()
           
} else {
    // Fallback on earlier versions
    // Try any other 3rd party or manual method here. 
}

```

### Step by Step

Now my opinion on a proper way of implementing RequestReview :

1- Create a new Swift file in your project 

2- Import required frameworks

```Swift
import Foundation
import StoreKit
```

3- Define setting variables 

```
let runIncrementerSetting = "numberOfRuns"  // UserDefauls dictionary key where we store number of runs
let minimumRunCount = 5                     // Minimum number of runs that we should have until we ask for review
```

4- Then create a manual run counter which simply stores number of runs in UserDefaults. To make the counter you need two functions. One to read from UserDefaults the other to increment by one and store in UserDefaults. 

```
func incrementAppRuns() {                   // counter for number of runs for the app. You can call this from App Delegate
    
    let usD = UserDefaults()
    let runs = getRunCounts() + 1
    usD.setValuesForKeys([runIncrementerSetting: runs])
    usD.synchronize()
    
}

func getRunCounts () -> Int {               // Reads number of runs from UserDefaults and returns it.
    
    let usD = UserDefaults()
    let savedRuns = usD.value(forKey: runIncrementerSetting)
    
    var runs = 0
    if (savedRuns != nil) {
        
        runs = savedRuns as! Int
    }
    
    print("Run Counts are \(runs)")
    return runs
    
}

```

5- The next would be a function to request for review. We have to consider two factors in this function. First, if we had enough number of runs to ask for review. Second, to check if we are running on iOS10.3 and higher so we can use the function. 

``` Swift
func showReview() {
    
    let runs = getRunCounts()
    print("Show Review")
    
    if (runs > minimumRunCount) {
        
        if #available(iOS 10.3, *) {
            print("Review Requested")
            SKStoreReviewController.requestReview()
            
        } else {
            // Fallback on earlier versions
        }
        
    } else {
        
        print("Runs are not enough to request review!")
        
    }
    
}

```
6- Next step is to call our run counter from App Delegate. So add the following in your App’s didFinishLaunchingWithOptions function

```Swift
 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        incrementAppRuns()
        return true
 }

```
7- The final step is to call showReview() in a proper time. I would suggest to call this function whenever user has accomplished a major work in the app. For example if you have a game, after you show results to the user you can call this function. Remember to call this function beside other jobs if you put it in a button callback. For example, in CMath, I put the showReview() function in back button of summary page. So when user have seen the results and tries to go to home page, the app takes the user to home page and if the requestReview method decides to show review, it will show the review dialog. This way we make sure our button always work properly, and also we show review request page when we are sure the user has done some major work in the app.  

```Swift
showReview()

```

**Voila!** Now you can run your app and see the result. 

To make your job easier, you can download my script from Github which covers steps 1-5 of this tutorial. [Click here to download the code.](https://github.com/Behrad3d/B2_Tutorials/tree/master/01_SwiftRequestReview)

--- 
#### Don't forget to include your comments below, Upvote and Resteem. Happy coding!
👍  , , , , , , , , , ,
properties (23)
post_id23,371,108
authorb2travel
permlinkstep-by-step-swift-tutorial-proper-way-to-request-review-using-skstorereviewcontroller-in-ios-10-3-and-higher
categorytutorial
json_metadata"{"app": "steemit/0.1", "format": "markdown", "links": ["https://github.com/Behrad3d/B2_Tutorials/tree/master/01_SwiftRequestReview"], "image": ["https://steemitimages.com/DQmZ4v19WroKV2t1qhgPZTEszwsScMH2ZJZukg2Vsr3RrLb/1491598043191.png"], "tags": ["tutorial", "swift", "xcode", "ios", "technology"]}"
created2018-01-03 19:29:03
last_update2018-01-03 20:08:21
depth0
children3
net_rshares16,079,461,803
last_payout2018-01-10 19:29:03
cashout_time1969-12-31 23:59:59
total_payout_value0.154 SBD
curator_payout_value0.023 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length6,564
author_reputation780,229,240,448
root_title"Step by Step Swift Tutorial: Proper way to request review using SKStoreReviewController in iOS 10.3 and higher"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (11)
@resteemable ·
**Your Post Has Been Featured on @Resteemable!** <br> Feature any Steemit post using resteemit.com! <br> **How It Works:** <br> 1. Take Any Steemit URL <br> 2. Erase `https://` <br> 3. Type `re`<br> Get Featured Instantly – Featured Posts are voted every 2.4hrs <br>[Join the Curation Team Here](streemian.com/profile/curationtrail/trailing/943)
properties (22)
post_id23,385,450
authorresteemable
permlinkre-resteemable-step-by-step-swift-tutorial-proper-way-to-request-review-using-skstorereviewcontroller-in-ios-10-3-and-higher-20180103t210053776z
categorytutorial
json_metadata{}
created2018-01-03 21:00:54
last_update2018-01-03 21:00:54
depth1
children0
net_rshares0
last_payout2018-01-10 21:00:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length345
author_reputation711,577,524,471
root_title"Step by Step Swift Tutorial: Proper way to request review using SKStoreReviewController in iOS 10.3 and higher"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@b2travel ·
@originalworks
properties (22)
post_id23,655,491
authorb2travel
permlinkre-b2travel-step-by-step-swift-tutorial-proper-way-to-request-review-using-skstorereviewcontroller-in-ios-10-3-and-higher-20180105t033123772z
categorytutorial
json_metadata"{"app": "steemit/0.1", "users": ["originalworks"], "tags": ["tutorial"]}"
created2018-01-05 03:31:24
last_update2018-01-05 03:31:24
depth1
children1
net_rshares0
last_payout2018-01-12 03:31:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length14
author_reputation780,229,240,448
root_title"Step by Step Swift Tutorial: Proper way to request review using SKStoreReviewController in iOS 10.3 and higher"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@originalworks ·
originalworks
The @OriginalWorks bot has determined this post by @b2travel to be original material and upvoted it! 
<center>![ezgif.com-resize.gif](https://steemitimages.com/DQmaBi37A5oTnQ9NBLH8YU4jpvhhmFauyvgg3YRrEJwskM9/ezgif.com-resize.gif)</center> 

To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!
properties (22)
post_id23,656,310
authororiginalworks
permlinkre-re-b2travel-step-by-step-swift-tutorial-proper-way-to-request-review-using-skstorereviewcontroller-in-ios-10-3-and-higher-20180105t033123772z-20180105t033651
categorytutorial
json_metadata"{"app": "pysteem/0.5.4"}"
created2018-01-05 03:36:51
last_update2018-01-05 03:36:51
depth2
children0
net_rshares0
last_payout2018-01-12 03:36:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length344
author_reputation79,229,860,066,508
root_title"Step by Step Swift Tutorial: Proper way to request review using SKStoreReviewController in iOS 10.3 and higher"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000