How can I add a link for a rate button with swift?

IosSwiftApp Store

Ios Problem Overview


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

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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

Solution 3 - Ios

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)

Solution 4 - Ios

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

Solution 5 - Ios

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.

Solution 6 - Ios

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)")!);
}

Solution 7 - Ios

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

Solution 8 - Ios

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.

Solution 9 - Ios

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

Solution 10 - Ios

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 .

Solution 11 - Ios

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

Solution 12 - Ios

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.

Solution 13 - Ios

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLuis FelipeView Question on Stackoverflow
Solution 1 - IosYannStephView Answer on Stackoverflow
Solution 2 - IosSimonView Answer on Stackoverflow
Solution 3 - IosAhmadrezaView Answer on Stackoverflow
Solution 4 - IosArvindView Answer on Stackoverflow
Solution 5 - IosThiagoAMView Answer on Stackoverflow
Solution 6 - IosMahmud AhsanView Answer on Stackoverflow
Solution 7 - IosSergPanovView Answer on Stackoverflow
Solution 8 - IosCliff WeitzmanView Answer on Stackoverflow
Solution 9 - IosmatiasverdeView Answer on Stackoverflow
Solution 10 - IosKrunal DarjiView Answer on Stackoverflow
Solution 11 - IosNavdeep PaliwalView Answer on Stackoverflow
Solution 12 - IosJakub TruhlářView Answer on Stackoverflow
Solution 13 - IosMax NiagolovView Answer on Stackoverflow