Launching App Store from App in Swift

前端 未结 9 994
情深已故
情深已故 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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))
        }
    }
    

提交回复
热议问题