Swift - 获取应用名称、应用版本、设备型号、系统版本等信息
1,效果图

2,样例代码
|
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 UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() //应用程序信息 let infoDictionary = Bundle.main.infoDictionary! let appDisplayName = infoDictionary["CFBundleDisplayName"] //程序名称 let majorVersion = infoDictionary["CFBundleShortVersionString"]//主程序版本号 let minorVersion = infoDictionary["CFBundleVersion"]//版本号(内部标示) let appVersion = majorVersion as! String //设备信息 let iosVersion = UIDevice.current.systemVersion //iOS版本 let identifierNumber = UIDevice.current.identifierForVendor //设备udid let systemName = UIDevice.current.systemName //设备名称 let model = UIDevice.current.model //设备型号 let modelName = UIDevice.current.modelName //设备具体型号 let localizedModel = UIDevice.current.localizedModel //设备区域化型号如A1533 //打印信息 print("程序名称:\(appDisplayName)") print("主程序版本号:\(appVersion)") print("内部版本号:\(minorVersion)") print("iOS版本:\(iosVersion)") print("设备udid:\(identifierNumber)") print("设备名称:\(systemName)") print("设备型号:\(model)") print("设备具体型号:\(modelName)") print("设备区域化型号:\(localizedModel)") } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() }}//扩展UIDeviceextension UIDevice { //获取设备具体详细的型号 var modelName: String { var systemInfo = utsname() uname(&systemInfo) let machineMirror = Mirror(reflecting: systemInfo.machine) let identifier = machineMirror.children.reduce("") { identifier, element in guard let value = element.value as? Int8, value != 0 else { return identifier } return identifier + String(UnicodeScalar(UInt8(value))) } switch identifier { case "iPod5,1": return "iPod Touch 5" case "iPod7,1": return "iPod Touch 6" case "iPhone3,1", "iPhone3,2", "iPhone3,3": return "iPhone 4" case "iPhone4,1": return "iPhone 4s" case "iPhone5,1", "iPhone5,2": return "iPhone 5" case "iPhone5,3", "iPhone5,4": return "iPhone 5c" case "iPhone6,1", "iPhone6,2": return "iPhone 5s" case "iPhone7,2": return "iPhone 6" case "iPhone7,1": return "iPhone 6 Plus" case "iPhone8,1": return "iPhone 6s" case "iPhone8,2": return "iPhone 6s Plus" case "iPhone9,1": return "iPhone 7 (CDMA)" case "iPhone9,3": return "iPhone 7 (GSM)" case "iPhone9,2": return "iPhone 7 Plus (CDMA)" case "iPhone9,4": return "iPhone 7 Plus (GSM)" case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4":return "iPad 2" case "iPad3,1", "iPad3,2", "iPad3,3": return "iPad 3" case "iPad3,4", "iPad3,5", "iPad3,6": return "iPad 4" case "iPad4,1", "iPad4,2", "iPad4,3": return "iPad Air" case "iPad5,3", "iPad5,4": return "iPad Air 2" case "iPad2,5", "iPad2,6", "iPad2,7": return "iPad Mini" case "iPad4,4", "iPad4,5", "iPad4,6": return "iPad Mini 2" case "iPad4,7", "iPad4,8", "iPad4,9": return "iPad Mini 3" case "iPad5,1", "iPad5,2": return "iPad Mini 4" case "iPad6,7", "iPad6,8": return "iPad Pro" case "AppleTV5,3": return "Apple TV" case "i386", "x86_64": return "Simulator" default: return identifier } }} |
原文出自:www.hangge.com 转载请保留原文链接:http://www.hangge.com/blog/cache/detail_1606.html
Swift - 获取应用名称、应用版本、设备型号、系统版本等信息的更多相关文章
- iOS获取设备型号、设备类型等信息
摘自 :http://www.mamicode.com/info-detail-1165460.html 设备标识 关于设备标识,历史上盛行过很多英雄,比如UDID.Mac地址.OpenUDID等,然 ...
- android API版本对应的系统版本及Android获取手机和系统版本等信息的代码
学了这么久的Android,竟然一直对其API对应的名称关系一值搞不清楚,现在网上认真看了下资料,转载一个觉得写得不错的作者的文章,记下来: [背景] 之前折腾android期间,慢慢地知道了,And ...
- iOS开发-获取设备型号信息
开发中有的时候查看设计统计数据,或者通过日志查看错误信息,这个时候我们就需要获取获取设备信息,看下关于设备有几种方法: NSLog(@"%@",[[UIDevice current ...
- iOS获取设备型号、装置类型等信息
iOS获取设备型号.设备类型等信息 设备标识 关于设备标识,历史上盛行过很多英雄,比如UDID.Mac地址.OpenUDID等,然而他们都陆陆续续倒在了苹果的门下.苹果目前提供了2个方法供App获取设 ...
- php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等
php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等 <?php header("Content-type: text/html; charset=utf-8" ...
- iOS获取设备型号和App版本号等信息(OC+Swift)
iOS获取设备型号和App版本号等信息(OC+Swift) 字数1687 阅读382 评论3 喜欢10 好久没有写过博客了,因为中间工作比较忙,然后有些个人事情所以耽误了.但是之前写的博客还一直有人来 ...
- iOS 获取手机的型号,系统版本,软件名称,软件版本
转载自:http://www.2cto.com/kf/201210/162333.html 网上搜索出来的,记录下来以后使用方便: [java]//手机序列号 NSString* ide ...
- IOS 获取最新设备型号方法
1.IOS 获取最新设备型号方法列表最新对照表:http://theiphonewiki.com/wiki/Models方法: #import "sys/utsname.h” struct ...
- ?Swift获取手机设备信息
使用UiDevice获取设备信息: 获取设备名称 let name = UIDevice.currentDevice().name 获取设备系统名称 let systemName = UIDevice ...
随机推荐
- WPF Menu控件自定义Style
自定义WPF中Menu控件的样式
- [Offer收割]编程练习赛36
逃离单身节 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector&g ...
- (转)Java进阶java int与Integer的区别
Java进阶java int与Integer的区别 前言 int与Integer的区别从大的方面来说就是基本数据类型与其包装类的区别: int 是基本类型,直接存数值,而Integer是对象,用一个引 ...
- mybatis 高级映射和spring整合之查询缓存(5)
mybatis 高级映射和spring整合之查询缓存(5) 2.0 查询缓存 2.0.1 什么是查询缓存 mybatis提供缓存,用于减轻数据压力,提高数据库性能. mybatis提供一级缓存和二级缓 ...
- UBuntu安裝使用PIP
Windows下安裝python包還是比較方便的,直接在FLD網站下載對應的EXE文件就可以安裝,在linux系統下,使用pip,easy egg 管理工具可以減輕安裝負擔. 原文鏈接:http:// ...
- 01--[转]C++强大背后
[转]C++强大背后 2014-01-22 分类:互联网 阅读(9295) 评论(6) 在31年前(1979年),一名刚获得博士学位的研究员,为了开发一个软件项目发明了一门新编程语言,该研究员名为Bj ...
- socket 的通信过程
1.建立套接字 Linux在利用socket()系统调用建立新的套接字时,需要传递套接字的地址族标识符.套接字类型以及协议,其函数定义于net/socket.c中: asmlinkage long s ...
- js 或运算
表达式a && 表达式b : 计算表达式a(也可以是函数)的运算结果, 如果为 True, 执行表达式b(或函数),并返回b的结果: 如果为 False,返回a的结果: 表达式a || ...
- CentOS7环境RabbitMQ集群配置管理(转载)
CentOS7环境RabbitMQ集群配置管理(转载) CentOS7系统内核版本:3.10.0-514.26.2.el7.x86_64 一.对应主机host地址(三台主机host文件要保持一致) ...
- 路飞学城Python-Day115
个人博客搭建 from django.db import models from django.contrib.auth.models import User, AbstractUser # Crea ...