Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 945
Luis Felipe Avatar asked Jan 03 '15 12:01

Luis Felipe


People also ask

How do I connect a button in Swift?

swift in your assistant editor. You can do this by holding Option on your keyboard and clicking the ViewController. swift file in your Project Navigator. Now click on the button, hold CTRL and then drag it to your Swift file.

How do I link to my app store review?

Go to App Information section (it should automatically take you there) At the bottom of that page, there is a blue link that says View on App Store . Click it and it will open to a blank page. Copy what is in the URL bar at the top of the page and that's your app reviews link.


2 Answers

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
like image 95
YannSteph Avatar answered Sep 25 '22 22:09

YannSteph


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") } 
like image 22
Simon Avatar answered Sep 25 '22 22:09

Simon