iOS OC 获取当前设备信息

这篇博客介绍了如何在Objective-C中获取iOS设备的各种详细信息,包括手机型号、设备像素比、屏幕宽高、可用窗口尺寸、客户端版本、操作系统版本、系统语言、MAC地址以及IP地址等,为iOS应用适配和调试提供了关键数据。
摘要由CSDN通过智能技术生成

// model 手机型号

// pixelRatio 设备像素比

// screenWidth 屏幕宽度

// screenHeight 屏幕高度

// windowWidth 可用窗口宽度

// windowHeight 可用窗口宽度

// version 客户端版本

// appPackage 客户端 package

// system 操作系统版本

// SDKVersion 客户端 sdk 版本

// language 系统语言 “zh-CN”

// platform 客户端平台

// MACAddress 物理地址、硬件地址

// ipAddress Ip 地址

.h

//获取设备型号
//可根据https://www.theiphonewiki.com/wiki/Models#iPhone添加

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface SystemInfomation : NSObject

//    model    手机型号
//    pixelRatio    设备像素比
//    screenWidth    屏幕宽度
//    screenHeight    屏幕高度
//    windowWidth    可用窗口宽度
//    windowHeight    可用窗口宽度
//    version    客户端版本
//    appPackage    客户端 package
//    system    操作系统版本
//    SDKVersion    客户端 sdk 版本
//    language    系统语言 "zh-CN"
//    platform    客户端平台
//    MACAddress    物理地址、硬件地址
//    ipAddress    Ip 地址

+ (NSDictionary *)deviceInfo;

+ (NSString*)getDeviceType;

+ (NSString *)getOSVersion;

+ (NSString*)getDeviceModel;

+ (NSString*)getPixelRatio;

+ (NSString *)getDeviceDisplayMetrics;

+ (NSString *)cpuArchitectures;

+(NSString*)getBundleID;

+ (NSString *)getApplicationName;

+ (NSString*)getLocalAppVersion;

+ (NSString *)getMacAddress;

+ (NSString *)getIPAdress;

+ (NSString *)getDeviceLanguage;

+ (CGFloat)getBatteryLevel;

+ (NSString *)getBatteryState;

@end

NS_ASSUME_NONNULL_END

.m

#import "SystemInfomation.h"
#import <sys/socket.h>
#import <sys/sysctl.h>
#import <sys/utsname.h>
#import <net/if.h>
#import <net/if_dl.h>
#import <CommonCrypto/CommonDigest.h>
#import <objc/runtime.h>
#import <ifaddrs.h>
#import <netinet/in.h>
#import <arpa/inet.h>

@implementation SystemInfomation


//    model    手机型号
//    pixelRatio    设备像素比
//    screenWidth    屏幕宽度
//    screenHeight    屏幕高度
//    windowWidth    可用窗口宽度
//    windowHeight    可用窗口宽度
//    version    客户端版本
//    appPackage    客户端 package
//    system    操作系统版本
//    SDKVersion    客户端 sdk 版本
//    language    系统语言 "zh-CN"
//    platform    客户端平台
//    MACAddress    物理地址、硬件地址
//    ipAddress    Ip 地址

+ (NSDictionary *)deviceInfo
{
    NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
    
    [dic setObject:[SystemInfomation getDeviceType] forKey:@"model"];
    [dic setObject:[SystemInfomation getPixelRatio] forKey:@"pixelRatio"];
    [dic setObject:[SystemInfomation getScreenWidth] forKey:@"screenWidth"];
    [dic setObject:[SystemInfomation getScreenH] forKey:@"screenHeight"];
    [dic setObject:[SystemInfomation getLocalAppVersion] forKey:@"version"];
    [dic setObject:[SystemInfomation getApplicationName] forKey:@"appPackage"];
    [dic setObject:[SystemInfomation getOSVersion] forKey:@"system"];
    [dic setObject:[SystemInfomation getDeviceLanguage] forKey:@"language"];
    [dic setObject:[SystemInfomation getOSType] forKey:@"platform"];
    [dic setObject:[SystemInfomation getMacAddress] forKey:@"MACAddress"];
    [dic setObject:[SystemInfomation getIPAdress] forKey:@"ipAddress"];
    
    return dic;
}

//获取设备型号
//可根据https://www.theiphonewiki.com/wiki/Models#iPhone添加
+ (NSString*)getDeviceType
{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    //iPhone
    if ([deviceString isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
    if ([deviceString isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    if ([deviceString isEqualToString:@"iPhone2,1"])    return @"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值