71

First I don't know how to get the link before I submit my app, and if the link is for each country app store or is it universal?

Also I don't know if the way to do it is just by putting the link there like:

@IBAction func rate(sender: AnyObject) {
    UIApplication.sharedApplication().openURL(NSURL(string : "webLinkHere")!)
}

Or should I use another way to do this?

Thanks

Luis Felipe
  • 891
  • 1
  • 9
  • 18
  • 4
    Goto your itunesconnect account -> My Apps -> Click on "+" Button ->New iOS App -> Fill require details -> After filling all details goto your App -> Click on More Button -> View on AppStore -> it will redirect you to your App URL this will be universal & will be same after your app goes live . – Krunal Darji Jan 03 '15 at 13:04
  • Thanks a lot, so I will just put my link where I put "webLinkHere" and it will work right? – Luis Felipe Jan 03 '15 at 13:11
  • Ya so it will redirect you to ur app, you should Up Vote my answer – Krunal Darji Jan 03 '15 at 13:12
  • I tried your answer but itunes say's The item you requested is currently not available in Indian or US store - @Krunal Darji – amar Sep 04 '17 at 07:56
  • 1
    @amar read the question carefully – Krunal Darji Sep 04 '17 at 08:56
  • Yes I got it @karun Darji – amar Sep 04 '17 at 09:29

13 Answers13

141

Try This, change appId in your method by your App ID

Swift 5

import StoreKit

func rateApp() {
    if #available(iOS 10.3, *) {
        SKStoreReviewController.requestReview()

    } else if let url = URL(string: "itms-apps://itunes.apple.com/app/" + "appId") {
        if #available(iOS 10, *) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)

        } else {
            UIApplication.shared.openURL(url)
        }
    }
}

Swift 3 \ 4

func rateApp() {
    guard let url = URL(string: "itms-apps://itunes.apple.com/app/" + "appId") else {
        return
    }
    if #available(iOS 10, *) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)

    } else {
        UIApplication.shared.openURL(url)
    }
}

id959379869 This is the id when you go on your Itune page of your app

Example : https://itunes.apple.com/fr/app/hipster-moustache/id959379869?mt=8

How get the ID :

  1. Itunesconnect account
  2. My Apps
  3. Click on "+" Button
  4. New iOS App
  5. Fill require details
  6. After filling all details goto your App
  7. Click on More Button
  8. View on AppStore
  9. It will redirect you to your App URL this will be universal
  10. Look Http URL
YannSteph
  • 9,590
  • 3
  • 49
  • 46
  • 3
    I have a live app on the App Store. The above code works 100%. I have tested it a moment ago. For those looking for a **current** solution, this it it :-) – Paul Metas Mar 06 '16 at 22:27
  • 2
    The guard on iOS 10 seems unecessary? – thibaut noah May 12 '17 at 09:38
  • @thibautnoah The guard is useful – YannSteph Jul 12 '17 at 11:59
  • 1
    @YannickSteph if you follow the guidelines it isn't and an if statement should be used instead – thibaut noah Jul 13 '17 at 10:53
  • 1
    This is the only one that worked for me in this post using Swift4, thanks! – Brewski Jun 08 '18 at 07:22
  • 1
    Awesome answer but why don't use SKStoreReviewController with a logic controlled by the app launch count or something similar?? – WoNDeR Apr 19 '19 at 12:52
  • 1
    Dont forget import StoreKit – RJB Jun 11 '19 at 18:30
  • 4
    Apple documentation says exactly this regarding the use of SKStoreReviewController.requestReview. "Although you should call this method when it makes sense in the user experience flow of your app, the actual display of a rating/review request view is governed by App Store policy. Because this method may or may not present an alert, it's not appropriate to call it in response to a button tap or other user action." – TheTeacher33 Sep 14 '19 at 09:32
25

This is working the best for me. Directs the user straight to the 'Write A Review' composer of the application.

Swift 3.1 (Support for iOS10 and below)

Introduces new action=write-review

let appID = "959379869"

if let checkURL = URL(string: "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=\(appID)&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8") {
    open(url: checkURL)
} else {
    print("invalid url")
}

...

func open(url: URL) {
    if #available(iOS 10, *) {
        UIApplication.shared.open(url, options: [:], completionHandler: { (success) in
            print("Open \(url): \(success)")
        })
    } else if UIApplication.shared.openURL(url) {
            print("Open \(url)")
    }
}

Tested and works on Swift 2.2

let appID = "959379869" // Your AppID
if let checkURL = NSURL(string: "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=\(appID)&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8") {
    if UIApplication.sharedApplication().openURL(checkURL) {
        print("url successfully opened")
    }
} else {
    print("invalid url")
}
Simon
  • 1,895
  • 2
  • 19
  • 25
21

Now after iOS 10.3+

The SKStoreReviewController allows users to rate an app directly from within the app through a dialog box. The only downsite is that you can only request StoreKit to display the dialog, but can't be sure if it will.

import StoreKit

func requestToRate() {
    SKStoreReviewController.requestReview()
}
Arvind
  • 2,303
  • 1
  • 23
  • 44
  • this is the right answer. this is how apps with heavy traffic get thousands of reviews. – Lucas Chwe Apr 09 '19 at 19:33
  • SKStoreReviewController is a good way to get feedback on your app. However, you should be aware that the prompt will only be displayed to a user a maximum of three times within a 365-day period. More information on this: https://developer.apple.com/documentation/storekit/skstorereviewcontroller/requesting_app_store_reviews – Bhaumik Sep 14 '20 at 18:29
  • Sadly it's depricated on iOS 14 – Ahmadreza Sep 21 '20 at 07:12
18

Swift 4

let url = URL(string: "itms-apps:itunes.apple.com/us/app/apple-store/id\(YOURAPPID)?mt=8&action=write-review")!
UIApplication.shared.openURL(url)
Ahmadreza
  • 5,262
  • 2
  • 36
  • 55
13

You can use the following function and replace the APP_ID with your one. Calling this function will open the app in app store link and user will see the Review page where he can click and write a review easily.

func rateApp(){
   UIApplication.sharedApplication().openURL(NSURL(string : "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=\(APP_ID)&onlyLatestVersion=true&pageNumber=0&sortOrdering=1)")!);
}
YannSteph
  • 9,590
  • 3
  • 49
  • 46
Mahmud Ahsan
  • 1,313
  • 14
  • 15
  • Do APP_ID have format: "id912873918273" or "912873918273" or "com.Companyname.Appname" ? – vkalit Mar 05 '16 at 20:55
  • 3
    The AppStore opened, but it raise an error: `Your request produced an error. [newNullResponse]` – Tai Le Apr 21 '16 at 07:17
  • Now I just use this one: UIApplication.sharedApplication().openURL(NSURL(string : "https://itunes.apple.com/app/id_APPID")!) – Mahmud Ahsan Apr 23 '16 at 01:56
  • @MahmudAhsan there is an auto-completion error at the end of your link, an extra end of parenthese inside the string that shouldn't be here, since it is one character i cannot edit it. – thibaut noah Jul 13 '17 at 10:56
9

For iOS 10.3+ you can use SKStoreReviewController with simple dialog, and choose rating in alert-style window. To use it, you should import StoreKit library. So, universal way to rate your app inside itself is like this:

import StoreKit

func rateApp(){
   if #available(iOS 10.3, *) {
      SKStoreReviewController.requestReview()
   } else {
      guard let url = URL(string: "itms-apps://itunes.apple.com/ru/app/cosmeteria/id1270174484") else {
         return
      }

      if #available(iOS 10.0, *) {
         UIApplication.shared.open(url, options: [:], completionHandler: nil)
      } else {
         UIApplication.shared.openURL(url)
      }
   }
}

And when you try to launch it in simulator, you won't see App Store window, so try it on device and it gonna work. This way covers all iOS versions, using all abilities. And the part of path in you application address "/us/app" means your App Store localisation, for example "us" means USA. You can easily find your app id in address string just by opening app in App Store in any browser.To get the link, just copy address in browser. Changing "https://" for "itms-apps://" lets you to open app in App Store application, while "https" opens web page in Safari

Andrea Mugnaini
  • 8,880
  • 3
  • 34
  • 49
SergPanov
  • 249
  • 4
  • 7
  • 1
    `requestReview` is not guaranteed to show up each time in real device. – Amr Lotfy Apr 06 '18 at 08:09
  • This should be the new approved answer. Since 10.3 should be almost everyones target, this gets rid of the redirect ugliness and sends directly to the store. Very clean. – Jason Short Jul 28 '18 at 04:58
9

Swift 5.1: The following function sends your user directly to the review section of ANY store, not just on the American one:

func rateApp(id : String) {
    guard let url = URL(string : "itms-apps://itunes.apple.com/app/id\(id)?mt=8&action=write-review") else { return }
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    } else {
        UIApplication.shared.openURL(url)
    }
}

Usage:

rateApp(id: "1287000522")

Important Note: This doesn't work on simulator! Test it on a real device.

ThiagoAM
  • 1,062
  • 8
  • 16
7

WARNING: If you are running your app on a simulator

 UIApplication.sharedApplication().openURL(NSURL(string : "url")!) 

will not work because there is no app store in the simulator. In order to test this functionality you must run your app on a device.

Cliff Weitzman
  • 215
  • 3
  • 9
  • This is incorrect. The "openURL" function works on the simulator and devices. However, depending on the URL you supply, the simulator may not be able to handle it. – Sam Spencer Jul 07 '17 at 17:58
2

Swift 3

  func rateApp(){
UIApplication.shared.open(URL(string : "itms-apps://itunes.apple.com/app/id959379869")!, options: [:]) { (done) in
  // Handle results

}}

id959379869 This is the id when you go on your iTunes page of your app

1

Goto your itunesconnect account -> My Apps -> Click on "+" Button ->New iOS App -> Fill require details -> After filling all details goto your App -> Click on More Button -> View on AppStore -> it will redirect you to your App URL this will be universal & will be same after your app goes live .

Krunal Darji
  • 558
  • 1
  • 3
  • 11
  • https://itunes.apple.com/us/app/tap-dont-tap/id955251145?l=es&ls=1&mt=8 This is my link, it says US so now I don't know if it is universal – Luis Felipe Jan 03 '15 at 13:16
  • ya it's universal you go ahead with this , so currently you don't have approved binary that's why its showing item not available – Krunal Darji Jan 03 '15 at 13:17
0

All the above answers are not best practices they might be affecting your app store ratings. For best practice use the below code.

func ReviewAppController() {
    let alert = UIAlertController(title: "Feedback", message: "Are you enjoying our App?", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "Dismis", style: .cancel, handler: nil))
    alert.addAction(UIAlertAction(title: "Yes, i Love it!", style: .default, handler: {_ in
        SKStoreReviewController.requestReview()
    }))
    alert.addAction(UIAlertAction(title: "No, this sucks!", style: .default, handler: {_ in
        //Collect feedback
    }))
    present(alert, animated: true)
}
-1

This link opens your app page in the App Store and then presents the write review sheet.

itms-apps://itunes.apple.com/app/id[APP_ID]?action=write-review

You can find the APP_ID in the App Store Connect under the details of your app as Apple ID.

Jakub Truhlář
  • 15,319
  • 7
  • 65
  • 73
-1

In case you want to directly write a review rather than just open an app page:

    if let url = URL(string: "https://itunes.apple.com/in/app/\(yourappname)/id\(yourAppleAppId)?ls=1&mt=8&action=write-review") {
       if #available(iOS 10.0, *) {
           UIApplication.shared.open(url, options: [:], completionHandler: nil)
       } else {
           // Earlier versions
           if UIApplication.shared.canOpenURL(url as URL) {
              UIApplication.shared.openURL(url as URL)
           }
       }
    }
Max Niagolov
  • 584
  • 7
  • 24