How can I add a link for a rate button with swift?
Solution 1
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 :
- 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
- Look Http URL
Solution 2
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
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
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
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.
Comments
-
Luis Felipe almost 2 years
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 over 9 yearsitunes.apple.com/us/app/tap-dont-tap/… This is my link, it says US so now I don't know if it is universal
-
Krunal Darji over 9 yearsya it's universal you go ahead with this , so currently you don't have approved binary that's why its showing item not available
-
vkalit about 8 yearsDo APP_ID have format: "id912873918273" or "912873918273" or "com.Companyname.Appname" ?
-
Paul Metas about 8 yearsI 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 :-)
-
Tai Le almost 8 yearsThe AppStore opened, but it raise an error:
Your request produced an error. [newNullResponse]
-
Mahmud Ahsan almost 8 yearsNow I just use this one: UIApplication.sharedApplication().openURL(NSURL(string : "itunes.apple.com/app/id_APPID")!)
-
MQoder over 7 yearsThanks complete answer :). you did forget to actualy open the URL on the swift 3.0 example!
-
Simon over 7 yearsthanks @MQoder :) Updated it, along with support for the deprecated open function in iOS 10.
-
thibaut noah almost 7 yearsThe guard on iOS 10 seems unecessary?
-
thibaut noah almost 7 yearsyour reviewString isn't used anywhere mate
-
MBH almost 7 yearsBut the code should be tested, there is
reviewString
is not used. There is also\(success)
variable which is used but not declared in else statement -
Sam Spencer almost 7 yearsThis 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.
-
YannSteph almost 7 years@thibautnoah The guard is useful
-
thibaut noah almost 7 years@YannickSteph if you follow the guidelines it isn't and an if statement should be used instead
-
thibaut noah almost 7 years@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.
-
Markus over 6 yearsPLEASE, THIS SOLUTION WORKS EXCEPT FOR THE NEW APP STORE (iOS 11) I IMPLEMENTED AND TESTED THIS CODE ON iOS 9 AND iOS 10, BUT NOT WORK ON iOS 11.
-
Arvind over 6 yearsany solution that works for both IOS 11 and previous versions?
-
Amr Lotfy about 6 years
requestReview
is not guaranteed to show up each time in real device. -
Brewski almost 6 yearsThis is the only one that worked for me in this post using Swift4, thanks!
-
Jason Short over 5 yearsThis 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.
-
Lucas Chwe about 5 yearsthis is the right answer. this is how apps with heavy traffic get thousands of reviews.
-
Wo_0NDeR ᵀᴹ almost 5 yearsAwesome answer but why don't use SKStoreReviewController with a logic controlled by the app launch count or something similar??
-
RJB almost 5 yearsDont forget import StoreKit
-
Surendra Kumar almost 5 yearsI was using this URL in my old app but it is not working with iOS 11.* . What is the new URL now? Thank you!
-
Surendra Kumar almost 5 years@Alfi answer is working with swift4 and iOS 11.* device
-
TheTeacher33 over 4 yearsApple 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."
-
Bhaumik over 3 yearsSKStoreReviewController 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: developer.apple.com/documentation/storekit/…
-
Ahmadreza over 3 yearsSadly it's depricated on iOS 14
-
Mrugesh Tank almost 3 yearsPerfect, this is what I was looking for.
-
ChuckZHB over 2 yearsThis works, I just test it on my live app in App Store.