美文网首页
iOS检测版本更新(Swift2.2)

iOS检测版本更新(Swift2.2)

作者: 断忆残缘 | 来源:发表于2016-06-08 13:58 被阅读301次

最近刚刚学了Swift,然后就用Swift做了一个公司的项目。中途也算是曲折不断了。实话说,Swift真的好用,现在的我已经不想再用oc做开发,我觉代替oc也就是一两年的事吧!废话不多说,切入正题。

1.获取已经上架的App版本信息(腾讯QQ为例)
2.与当前安装的版本作比较
3.决定是否要跳转到App Store 进行下载

以下是我参照的一个前辈的OC版本进行修改的

        let url = "http://itunes.apple.com/cn/lookup?id=444934666"
        postpath(url)
func postpath(path: String) {
        let url = NSURL(string: path)
        let request = NSMutableURLRequest(URL: url!, cachePolicy: .ReloadIgnoringCacheData, timeoutInterval: 10)
        request.HTTPMethod = "POST"
        let queue = NSOperationQueue()
        NSURLConnection.sendAsynchronousRequest(request, queue: queue) { (response, data, error) in
            var receiveStatusDic = [String: AnyObject]()
            if data != nil {
                var receiveDic = [String: AnyObject]()
                do {
                    receiveDic = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves) as! [String : AnyObject]
                } catch {
                    print(error)
                }
                
                if receiveDic["resultCount"]?.integerValue > 0 {
                    receiveStatusDic["status"] = "1"
                    
                } else {
                    receiveStatusDic["status"] = "-1"
                }
            } else {
                receiveStatusDic["status"] = "-1"
            }
            self.performSelectorOnMainThread(#selector(ViewController.receiveData(_:)), withObject: receiveStatusDic, waitUntilDone: false)
        }
        
    }
func receiveData(sender: [String: AnyObject]) {
        print("receiveData=\(sender)")
        let infoDictionary = NSBundle.mainBundle().infoDictionary
        // app版本
        let app_Version = infoDictionary!["CFBundleShortVersionString"] as? String
        if app_Version != (sender["version"] as? String) {
            let alert = UIAlertController(title: "提示", message: "版本有更新", preferredStyle: .Alert)
            let action_sure = UIAlertAction(title: "更新", style: .Default) { (action) in
                let url = NSURL(string: "https://itunes.apple.com/cn/app/qq-2011/id444934666?mt=8")
                UIApplication.sharedApplication().openURL(url!)
            }
            let action_cancel = UIAlertAction(title: "取消", style: .Cancel, handler: nil)
            alert.addAction(action_sure)
            alert.addAction(action_cancel)
            
            presentViewController(alert, animated: true, completion: nil)
            
        }
        
        
    }

最后给大家一个swift和oc代码互转的网页,我在stack overflow交流问题的时候热心的网友给的。(转化中还是有些小问题吧,不过可以用的!)https://objectivec2swift.com/#/home/converter/

相关文章

  • iOS检测版本更新(Swift2.2)

    最近刚刚学了Swift,然后就用Swift做了一个公司的项目。中途也算是曲折不断了。实话说,Swift真的好用,现...

  • iOS检测版本更新

    利用iTunes接口检查App版本更新

  • iOS 检测版本更新

  • iOS检测版本更新

    效果图 具体实现代码参考源码https://github.com/wolfhous/HSUpdateApp 文件小...

  • iOS 版本检测更新

  • iOS 检测版本更新

    在苹果的 app store 条文中,是不允许新版本提示的, 但是只要不让那些审核员知道有这个功能就可以了。启动的...

  • iOS 检测版本更新

    基于良好的用户体验,当在appStroe上线了新的版本时,提醒用户更新”新版本“是必不可少的。 版本更新的...

  • iOS检测版本更新

    效果图 具体实现代码参考源码https://github.com/wolfhous/HSUpdateApp 文件小...

  • iOS 版本检测更新

    iOS7开始就添加了应用自动更新,该提示更新适用于用户关闭了自动更新应用功能的情况下,现实中很多iPhone用户都...

  • iOS 版本检测更新

    每个正在迭代更新的项目,都必不可少的要检测是否发布了最新的版本,来保证以最优化的版本服务用户。其实我并不赞成一打开...

网友评论

      本文标题:iOS检测版本更新(Swift2.2)

      本文链接:https://www.haomeiwen.com/subject/awjjdttx.html