Launching App Store from App in Swift

前端 未结 9 992
情深已故
情深已故 2020-12-31 01:43

I am creating an app, and I have a banner which promotes my other app. This is my code:

var barsButton : UIButton = UIButton(frame: CGRectMake((self.view.bou         


        
相关标签:
9条回答
  • 2020-12-31 02:14

    Simply you can use these functions in a utility struct to goto app page in app store also you can goto rate app view directly:

    static func gotoApp(appID: String, completion: ((_ success: Bool)->())? = nil) {
        let appUrl = "itms-apps://itunes.apple.com/app/id\(appID)"
    
        gotoURL(string: appUrl, completion: completion)
    }
    
    static func rateApp(appId: String, completion: ((_ success: Bool)->())? = nil) {
        //let appUrl = "itms-apps://itunes.apple.com/app/" + appId
        let appUrl = "https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=\(appId)&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"
        //TODO: use &action=write-review for opening review directly
        print("app review URL: ", appUrl)
    
        gotoURL(string: appUrl, completion: completion)
    }
    
    static func gotoURL(string: String, completion: ((_ success: Bool)->())? = nil) {
        print("gotoURL: ", string)
        guard let url = URL(string: string) else {
            print("gotoURL: invalid url", string)
            completion?(false)
            return
        }
        if #available(iOS 10, *) {
            UIApplication.shared.open(url, options: [:], completionHandler: completion)
        } else {
            completion?(UIApplication.shared.openURL(url))
        }
    }
    
    0 讨论(0)
  • 2020-12-31 02:14

    As openURL is deprecated from iOS 10 use below code:

    UIApplication.shared.open((URL(string: "itms://itunes.apple.com/app/" + appStoreAppID)!), options:[:], completionHandler: nil)
    
    0 讨论(0)
  • 2020-12-31 02:18

    I use this and it works.

    let locale: String = Locale.current.regionCode ?? "US"
    UIApplication.shared.open(URL(string: "https://apps.apple.com/\(locale)/developer/{developer-name}/{idXXXXXXXXXX}")!, options: [:], completionHandler: nil)
    
    0 讨论(0)
  • 2020-12-31 02:23

    Link you are trying to open is not valid - remove https: schema from it (or itms: - but I suggest first option, to avoid redirects)

    0 讨论(0)
  • 2020-12-31 02:24

    You have too many protocols in your URL. Get rid of https: so the URL reads

    itms-apps://itunes.apple.com/app/bars/id706081574

    0 讨论(0)
  • 2020-12-31 02:24

    I had this problem but this code just works on the phone not simulator. So check this code:

    if let url = URL(string: "itms-apps://itunes.apple.com/app/id" + APP_ID ),
        UIApplication.shared.canOpenURL(url){
        UIApplication.shared.openURL(url)
    }else{
        //Just check it on phone not simulator!
        print("Can not open")
    }
    
    0 讨论(0)
提交回复
热议问题