Open AppStore through button

前端 未结 15 772
逝去的感伤
逝去的感伤 2020-12-12 22:18

Could you guys help me to translate the following code into Swift?

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@\"itms://itunes.apple.com         


        
15条回答
  •  一向
    一向 (楼主)
    2020-12-12 22:34

    Swift 4 with completion handler:

    Make sure to update your id in the appStoreUrlPath

    func openAppStore() {
        if let url = URL(string: "itms-apps://itunes.apple.com/app/id..."),
            UIApplication.shared.canOpenURL(url){
            UIApplication.shared.open(url, options: [:]) { (opened) in
                if(opened){
                    print("App Store Opened")
                }
            }
        } else {
            print("Can't Open URL on Simulator")
        }
    }
    

提交回复
热议问题