swift 获取Appstore版本号并与本地版本比较 更新跳转到Appstore

本文介绍了一种使用Alamofire请求AppStore版本信息的方法,并实现了版本比较逻辑。当发现新版本时,会引导用户前往AppStore进行更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先我用的是Alamofire请求的数据

1.获取appstore版本号

func checkVersionTapGestrue(sender: UITapGestureRecognizer){
        Alamofire.request("https://itunes.apple.com/lookup?bundleId=你的bundleId", method: .get, parameters: [:])
            .responseJSON { (response) in
                
                if let value = response.result.value {
                    let json = JSON(value)
            
                    self.compareVersion(appStoreVersion: json["results"][0]["version"].stringValue)
                }
        }
    }

2.比较两个版本

//比较版本
    func compareVersion(appStoreVersion: String) {
    
        let version:String = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String)!

        if appStoreVersion == version {
            BaseController().showTextOnly(view: self.view, text: "当前已经是最新版本", detail: "")
        }else{
            let urlString = "itms-apps://itunes.apple.com/app/id23223232323"(id加你的appId)
            if let url = URL(string: urlString) {
                //根据iOS系统版本,分别处理
                if #available(iOS 10, *) {
                    UIApplication.shared.open(url, options: [:],
                                              completionHandler: {
                                                (success) in
                    })
                } else {
                    UIApplication.shared.openURL(url)
                }
            }
        }
    }    

参考:http://www.hangge.com/blog/cache/detail_1265.html

Alamofire

Alamofire

Alamofire

Alamofire

Alamofire

转载于:https://www.cnblogs.com/kunH/p/7340513.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值