本文共 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/