美文网首页
记录swift版 版本更新

记录swift版 版本更新

作者: Fenghao_耗子 | 来源:发表于2020-04-23 09:16 被阅读0次

//JSONString转字典

    funcgetDictFromString(jString:String) ->NSDictionary{

        letjsonData:Data= jString.data(using: .utf8)!

        letdict =try? JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers)

        ifdict !=nil{

            returndictas!NSDictionary

        }

            returnNSDictionary()

    }

    //版本更新

    funchsUpdateApp() {

        letappId:String="**********"

        //获取appstore上的最新版本号

        letappUrl = URL.init(string:"http://itunes.apple.com/lookup?id="+ appId)

        guardletappMsg =try? String.init(contentsOf: appUrl!, encoding: .utf8)else{

            return

        }

        letappMsgDict:NSDictionary= getDictFromString(jString: appMsg)

        letappResultsArray:NSArray= (appMsgDict["results"]as?NSArray)!

        letappResultsDict:NSDictionary= appResultsArray.lastObjectas!NSDictionary

        letappStoreVersion:String= appResultsDict["version"]as!String

        letfhappStoreVersion = appStoreVersion .replacingOccurrences(of:".", with:"")

        letappStoreVersion_Float:Float= Float(fhappStoreVersion)!

        //获取当前手机安装使用的版本号

        letlocalVersion:String= Bundle.main.infoDictionary!["CFBundleShortVersionString"]as!String

        letfhlocalVersion = localVersion .replacingOccurrences(of:".", with:"")

        letlocalVersion_Float:Float= Float(fhlocalVersion)!

        //appstore上的版本号大于本地版本号 - 说明有更新

        ifappStoreVersion_Float > localVersion_Float {

                    /*

弹框确认按钮事件

                letupdateUrl:URL= URL.init(string:"http://itunes.apple.com/app/id"+ appId)!

                 UIApplication.shared.open(updateUrl, options: [:], completionHandler:nil)

                    */

        }

    }

相关文章

网友评论

      本文标题:记录swift版 版本更新

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