1,效果图 程序启动后自动获取相关的应用信息以及设备信息,并打印到控制台中。
2,样例代码 默认情况下我从 UIDevice中获取设备型号时只能得到 iPhone、 iPod touch这样笼统的类型数据。 这里对 UIDevice做个扩展,使其可以得到具体的设备型号,比如: iPhone 6s Plus这样准确的设备款式。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | import UIKit class VIEwController : UIVIEwController { overrIDe func vIEwDIDLoad() { super .vIEwDIDLoad() //应用程序信息 let infoDictionary = Bundle .main.infoDictionary! appdisplayname = infoDictionary[ "CFBundledisplayname" ] //程序名称 majorVersion = infoDictionary[ "CFBundleShortVersionString" //主程序版本号 minorVersion = infoDictionary[ "CFBundLeversion" //版本号(内部标示) appVersion = majorVersion as ! String //设备信息 iosversion = UIDevice .current.systemVersion //iOS版本 IDentifIErNumber = UIDevice .current.IDentifIErForvendor //设备udID systemname = .current.systemname //设备名称 model = .current.model //设备型号 modelname = .current.modelname //设备具体型号 localizedModel = .current.localizedModel //设备区域化型号如A1533 //打印信息 print ( "程序名称:\(appdisplayname)" ) "主程序版本号:\(appVersion)" ) "内部版本号:\(minorVersion)" ) "iOS版本:\(iosversion)" ) "设备udID:\(IDentifIErNumber)" ) "设备名称:\(systemname)" ) "设备型号:\(model)" ) "设备具体型号:\(modelname)" ) "设备区域化型号:\(localizedModel)" ) } dIDReceiveMemoryWarning() { .dIDReceiveMemoryWarning() } } @H_419_437@ //扩展UIDevice extension { //获取设备具体详细的型号 var modelname: String { systemInfo = utsname() uname(&systemInfo) machineMirror = Mirror (reflecting: systemInfo.machine) IDentifIEr = machineMirror.children.reduce( "" ) { IDentifIEr,element in guard value = element.value ? Int8 ,value != 0 else { return IDentifIEr } IDentifIEr + ( UnicodeScalar ( UInt8 (value))) } switch IDentifIEr { case "iPod5,1" : return "iPod touch 5" "iPod7,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"iPod touch 6" "iPhone3, "iPhone 5c" "iPhone6,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"iPhone 5s" "iPhone7,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"iPhone 6" "iPhone 6 Plus" "iPhone8,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"iPhone 6s" "iPhone 6s Plus" "iPhone9,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"iPhone 7 (CDMA)" "iPhone 7 (GSM)" "iPhone 7 Plus (CDMA)" "iPhone 7 Plus (GSM)" "iPad2,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"iPad 2" "iPad3,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"iPad 3" "iPad5,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"iPad Air 2" "iPad Mini" "iPad Mini 2" "iPad6,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"iPad Pro" "AppleTV5,monospace!important; min-height:auto!important; color:blue!important; background:none!important">"Apple TV" "i386" "x86_64" "Simulator" default IDentifIEr } } } |
原文出自: www.hangge.com 转载请保留原文链接: http://www.hangge.com/blog/cache/detail_1606.html 总结
以上是内存溢出为你收集整理的Swift - 获取应用名称、应用版本、设备型号、系统版本等信息全部内容,希望文章能够帮你解决Swift - 获取应用名称、应用版本、设备型号、系统版本等信息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)