最近新开项目.需要上传一些设备信息.就写了这么多
获取设备的信息
NSLog(@"globallyUniqueString=%@",[[NSProcessInfoprocessInfo] globallyUniqueString]);//全球唯一标识NSLog(@"uniqueIdentifie=%@",[UIDevicecurrentDevice].uniqueIdentifier);//唯一的标识 可用于区分设备NSLog(@"name=%@",[UIDevicecurrentDevice].name);//设备的名称 谁的iPadNSLog(@"systemName=%@",[UIDevicecurrentDevice].systemName);//系统的名称 iPhone OSNSLog(@"systemVersion=%@",[UIDevicecurrentDevice].systemVersion);//设备系统的版本号NSLog(@"model=%@",[UIDevicecurrentDevice].model);//设备的型号 iPad、iphone、ipod touch。。。NSLog(@"localizedModel=%@",[UIDevicecurrentDevice].localizedModel);//本地化的模型 iPadNSLog(@"batteryLevel=%lf",[UIDevicecurrentDevice].batteryLevel);//电池电量
获取手机型号和系统号
/**获取手机型号和系统号*/+ (NSString*)getDeviceInfo{NSString*phoneVersion = [[UIDevicecurrentDevice] systemVersion];NSString*deviceInfo = [NSStringstringWithFormat:@"%@;%@",[selfgetPhoneDevice],phoneVersion];returndeviceInfo;}
获取iPhone和iPad的机型
+ (NSString *)getPhoneDevice{// 需要#import "sys/utsname.h"struct utsname systemInfo; uname(&systemInfo); NSString *deviceString = [NSStringstringWithCString:systemInfo.machineencoding:NSUTF8StringEncoding]; NSLog(@"型号:%@", deviceString);//iPhoneif([deviceStringisEqualToString:@"iPhone3,1"])return@"iPhone 4";if([deviceStringisEqualToString:@"iPhone3,2"])return@"Verizon iPhone 4";if([deviceStringisEqualToString:@"iPhone4,1"])return@"iPhone 4S";if([deviceStringisEqualToString:@"iPhone5,1"])return@"iPhone 5";if([deviceStringisEqualToString:@"iPhone5,2"])return@"iPhone 5";if([deviceStringisEqualToString:@"iPhone5,3"])return@"iPhone 5C";if([deviceStringisEqualToString:@"iPhone5,4"])return@"iPhone 5C";if([deviceStringisEqualToString:@"iPhone6,1"])return@"iPhone 5S";if([deviceStringisEqualToString:@"iPhone6,2"])return@"iPhone 5S";if([deviceStringisEqualToString:@"iPhone7,1"])return@"iPhone 6 Plus";if([deviceStringisEqualToString:@"iPhone7,2"])return@"iPhone 6";if([deviceStringisEqualToString:@"iPhone8,1"])return@"iPhone 6s";if([deviceStringisEqualToString:@"iPhone8,2"])return@"iPhone 6s Plus";if([deviceStringisEqualToString:@"iPhone8,4"])return@"iPhone SE";if([deviceStringisEqualToString:@"iPhone9,1"])return@"iPhone 7";if([deviceStringisEqualToString:@"iPhone9,3"])return@"iPhone 7";if([deviceStringisEqualToString:@"iPhone9,2"])return@"iPhone 7 Plus";if([deviceStringisEqualToString:@"iPhone9,4"])return@"iPhone 7 Plus";//iPadif([deviceStringisEqualToString:@"iPod1,1"])return@"iPod Touch 1G";if([deviceStringisEqualToString:@"iPod2,1"])return@"iPod Touch 2G";if([deviceStringisEqualToString:@"iPod3,1"])return@"iPod Touch 3G";if([deviceStringisEqualToString:@"iPod4,1"])return@"iPod Touch 4G";if([deviceStringisEqualToString:@"iPad1,1"])return@"iPad";if([deviceStringisEqualToString:@"iPad2,1"])return@"iPad 2 (WiFi)";if([deviceStringisEqualToString:@"iPad2,2"])return@"iPad 2 (GSM)";if([deviceStringisEqualToString:@"iPad2,3"])return@"iPad 2 (CDMA)";if([deviceStringisEqualToString:@"i386"])return@"Simulator";if([deviceStringisEqualToString:@"x86_64"])return@"Simulator";returndeviceString;}
获取屏幕尺寸
//ios版本号#defineIOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]//是否为iOS 7.0以上#defineIS_IOS7 [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0#defineIS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)#defineIS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)#defineIS_IPHONE_4_OR_LESS ([UIScreen mainScreen].bounds.size.height < 568.0)#defineIS_IPHONE_5 ([UIScreen mainScreen].bounds.size.height == 568.0)#defineIS_IPHONE_6 ([UIScreen mainScreen].bounds.size.height == 667.0)#defineIS_IPHONE_6P ([UIScreen mainScreen].bounds.size.height == 736.0)#defineIS_IPHONE_6_OR_LATER ([UIScreen mainScreen].bounds.size.height >= 667.0)
空的处理方式
//判断服务器返回为空#define checkIsNULL(__X__) (__X__) == [NSNullnull] || (__X__) == nil ? @"": [NSStringstringWithFormat:@"%@", (__X__)]-------------------------------------------------------//字符串是否为空#define kStringIsEmpty(str) ([str isKindOfClass:[NSNullclass]]||str==nil||[str length]<1?YES:NO)//数组是否为空#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNullclass]]||array.count==0)//字典是否为空#define kDictIsEmpty(dic) (dic.count ==0|| [dic isKindOfClass:[NSNullclass]]||dic.allKeys==0)//是否是空对象#define kObjectIsEmpty(_object) (_object == nil \|| [_object isKindOfClass:[NSNullclass]]\|| ([_object respondsToSelector:@selector(length)] && [(NSData*)_object length] ==0) \|| ([_object respondsToSelector:@selector(count)] && [(NSArray*)_object count] ==0))
防止循环引用
//弱引用/强引用
#define XLJWeakSelf(type)__weaktypeof(type)weak##type=type;
#define XLJStrongSelf(type)__strongtypeof(type)type= weak##type;