// 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 @"