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

前端 未结 13 713
面向向阳花
面向向阳花 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: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")
    }
    

提交回复
热议问题