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

前端 未结 13 694
面向向阳花
面向向阳花 2021-01-29 18:57

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

相关标签:
13条回答
  • 2021-01-29 19:29

    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)
    
    0 讨论(0)
  • 2021-01-29 19:30

    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()
    }
    
    0 讨论(0)
  • 2021-01-29 19:30

    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

    0 讨论(0)
  • 2021-01-29 19:38

    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.

    0 讨论(0)
  • 2021-01-29 19:39

    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")
    }
    
    0 讨论(0)
  • 2021-01-29 19:43

    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
    0 讨论(0)
提交回复
热议问题