iOS获取设备与APP信息——swift版

我是创建了一个单独的类(XLAppManager),用来处理获取设备与APP信息的相关内容,步骤如下:
1、创建继承自NSObject的一个类,将其命名为:XLAppManager;

2、将 XLAppManager 创建成一个单例:

static let shared = XLAppManager()
private override init() {}

3、将bundle字典信息设置成一个全局的常量:

/// app bundle信息
private let infoDictionary = Bundle.main.infoDictionary

4、实现相关内容:

/// 获取APP的名称
func getAppName() -> String {
return infoDictionary!["CFBundleDisplayName"] as! String
}

/// 获取APP bundleID
func getAppBundleId() -> String {
    return Bundle.main.bundleIdentifier!
}

/// 获取APP版本
func getAppVersion() -> String {
    return infoDictionary!["CFBundleShortVersionString"] as! String
}

/// 获取APP build版本
func getAppBuildVersion() -> String {
    return infoDictionary!["CFBundleVersion"] as! String
}

/// 获取手机序列号 UUID
func getDeviceIdentifierNumber() -> String {
    return (UIDevice.current.identifierForVendor?.uuidString)!
}

/// 获取手机型号
func getPhoneModel() -> String {
    return UIDevice.current.model
}

/// 获取手机系统版本
func getPhoneVersion() -> String {
    return UIDevice.current.systemVersion
}

/// 获取设备名称
func getDeviceName() -> String {
    return UIDevice.current.systemName
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容