博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
swift之获取APP各种参数和device参数、获取APPstore信息、以及跳转到appstore
阅读量:4290 次
发布时间:2019-05-27

本文共 4596 字,大约阅读时间需要 15 分钟。

============app信息和device信息==========

//获取appstore信息、获取app信息、获取手机设备信息import UIKitclass LYBGetAppinfoExtention: NSObject {}extension String{        //下载页、详情页面、评论页面的地址---如果不起效果:将 http:// 替换为 itms:// 或者 itms-apps://,注意用真机才有效果    static func gotoappstoreDetailAndStars(){           let urs="itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1123550373"       let url:URL?=URL.init(string: urs)        UIApplication.shared.open(url!, options:[:]) { (success) in                    }    }         //下载页,评分页---如果不起效果:将 http:// 替换为 itms:// 或者 itms-apps://,注意用真机才有效果    static  func  gotoappstoreStarandDownload(){      let urs="https://itunes.apple.com/app/id1123550373"      let url:URL?=URL.init(string: urs)        UIApplication.shared.open(url!, options:[:]) { (success) in                    }    }         //下载页,评分页---如果不起效果:将 http:// 替换为 itms:// 或者 itms-apps://,注意用真机才有效果    static func lookappstore(){        let urs="itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1123550373"        let url:URL?=URL.init(string: urs)        UIApplication.shared.open(url!, options:[:]) { (success) in                    }    }            //    ===============获取appstore中应用的信息========    /*调用     let s = String.getAppStoreInfo() as! [Any]  //返回的是一个数组,数组包含字典     let ss = s[0] as![String:Any] //数组只有一个元素,这个元素就是字典     print("\(String(describing: ss["version"]))")          */        static   func getAppStoreInfo() ->Any{//    要么改成https,//    要么info.plist加NSAppTransportSecurity.NSAllowsArbitraryLoads = true,//    获取信息的地址:    let appidStr:String="1123550373"    let appurlStr:String=String.init(format: "https://itunes.apple.com/cn/lookup?id=%@", appidStr)    let url:URL=URL.init(string: appurlStr)!    do{       let jsonData=try Data.init(contentsOf: url)       let json=try JSONSerialization.jsonObject(with: jsonData, options: []) as! [String:Any]       let res=json["results"]//APPstore信息//       print("\(String(describing: res))")        return res as Any      }catch{        return ""      }    }        //============获取app信息==============    static    func getInfodict()->[String:Any]{        let infoDic = Bundle.main.infoDictionary        return infoDic!    }    //获取app名字    static  func getappName(){         let appName: String = (Bundle.main.object(forInfoDictionaryKey: "CFBundleName")as!String?)!        Swift.print("\(appName)")    }        static  func getappbundId()->String{         //bundleID     let bundId:String=Bundle.main.bundleIdentifier!        Swift.print("\(bundId)")        return  bundId    }        static  func getappVersion()->String{    // 获取App的版本号---version(上线的版本号)      let infoDic=getInfodict()        let appVersion:String = infoDic["CFBundleShortVersionString"]! as! String        Swift.print("\(appVersion)")        return appVersion    }        static   func getappBuildVersion()->String{  // 获取App的build版本        let infoDic=getInfodict()     let appBuildVersion:String = infoDic["CFBundleVersion"]! as! String        Swift.print("\(appBuildVersion)")        return appBuildVersion    }        static   func getappNames()->String{ // 获取App的名称        let infoDic=getInfodict()     let appNames :String = infoDic["CFBundleName"]! as! String        Swift.print("\(appNames)")        return appNames    }        static  func getappDispaleyname()->String{ // app名称name,当displayname存在时,name显示为override,displayname不存在时,name正常显示        let infoDic=getInfodict()     let appDispaleyname:String  = infoDic["CFBundleDisplayName"]! as! String        print("\(appDispaleyname)")     return appDispaleyname    }         //============获取手机设备信息==============    static  func getidentifierNumber()->String{     //手机序列号(唯一标识)     let  identifierNumber:String  = (UIDevice.current.identifierForVendor?.uuidString)!     return identifierNumber    }        static  func getuserPhoneName()->String{     //手机别名:用户定义的名称      let  userPhoneName:String  = UIDevice.current.name        return userPhoneName    }        static  func getdeviceName()->String{     //设备名称      let deviceName:String  = UIDevice.current.systemName    return deviceName    }        static  func getphoneVersion()->String{      //手机系统版本      let phoneVersion:String  = UIDevice.current.systemVersion        return phoneVersion    }        static  func getphoneModel()->String{    //手机型号    let phoneModel:String  = UIDevice.current.model     return phoneModel    }        static   func getlocalPhoneModel()->String{     //地方型号 (国际化区域名称)     let localPhoneModel:String  = UIDevice.current.localizedModel     return localPhoneModel     }     }

 

 

转载地址:http://kimgi.baihongyu.com/

你可能感兴趣的文章
常用正则表达式大全
查看>>
JDK1.5(jdk5.0)新特性
查看>>
JDK1.6(jdk6.0)新特性
查看>>
java中的集合存储结构
查看>>
java中的集合存储结构
查看>>
Java基础——对象和类,类中的变量和方法
查看>>
谈谈JDBC
查看>>
jdbc_API中的说明
查看>>
jdbc_javax包
查看>>
Android 6.0 APIs_新特性(google官方)
查看>>
maxwell斗胆也来谈谈"学习方法“_转自黑马论坛
查看>>
XML解析
查看>>
AndroidManifest.xml详解
查看>>
activity的xml详解
查看>>
JNI 简介与实现-JavaNativeInterface
查看>>
ResourceBundle和Properties
查看>>
javascript *** is not a function
查看>>
老韩思考:卖点----卖豆腐的能转行IT
查看>>
Android_属性动画
查看>>
网络下载-xUtils,HttpUtils
查看>>