iphone-common-codes-ccteam源代码 CCUIDevice.m
来源:互联网 发布:德鲁迦雾化器口感数据 编辑:程序博客网 时间:2024/05/14 03:43
//// CCUIDevice.m// CCFC//// Created by xichen on 11-12-17.// Copyright 2011年 ccteam. All rights reserved.//#import "CCUIDevice.h"#import "CCIOS.h"#import "CCFileUtil.h"#import <AudioToolbox/AudioToolbox.h>#import <ifaddrs.h>#import <arpa/inet.h>#import <sys/sysctl.h>#import <sys/utsname.h>#if CC_ENABLE_PRIVATE_API@interface UIDevice(ccPrivate)- (NSString *)buildVersion;@end#endif@implementation UIDevice(cc)//获取OS版本+ (NSString *)osVersion{ return [CCIOS osVersion];}// 获取OS主版本号+ (NSString *)osMajorVer{ return [CCIOS osMajorVer];}// 获取OS子版本号+ (NSString *)osMinorVer{ return [CCIOS osMinorVer];}//振动设备+ (void)vibrate{ AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);}// whether the device is retina+ (BOOL)isRetina{ if([UIScreen instancesRespondToSelector:@selector(currentMode)]) return CGSizeEqualToSize(CGSizeMake(640,960), [[UIScreen mainScreen] currentMode].size); return NO;}// whether the device supports multitask+ (BOOL)isSupportsMultitask __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0){ return [[UIDevice currentDevice] isMultitaskingSupported];}// not ok// reboot the device// if you don't have the permission, then "Operation not permitted" will be logged.+ (int)reboot{ system("echo alpine | su root"); return system("reboot");}+ (void)disableAutoLock{ [[UIApplication sharedApplication] setIdleTimerDisabled:YES];}+ (void)enableAutoLock{ [[UIApplication sharedApplication] setIdleTimerDisabled:NO];}// create UUID+ (NSString *)createUUID{ CFUUIDRef uuidObj = CFUUIDCreate(kCFAllocatorDefault); NSString *uuidStr = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObj); CFRelease(uuidObj); return uuidStr;}// get the WAN IP address of the device based on ios+ (NSString *)getWANAddress{ return [self getIPAddressBy:@"pdp_ip0"]; }// get the Wifi IP address of the device based on ios+ (NSString *)getWifiAddress{ return [self getIPAddressBy:@"en0"]; }// get the IP address of the device based on ios by ifaName+ (NSString *)getIPAddressBy:(NSString *)ifaName{ struct ifaddrs *addrs; struct ifaddrs *cur; if(!getifaddrs(&addrs)) { cur = addrs; while (cur != NULL) { if(cur->ifa_addr->sa_family == AF_INET) { if (!strcmp(cur->ifa_name, [ifaName UTF8String])) return [NSString stringWithUTF8String: inet_ntoa(((struct sockaddr_in *)cur->ifa_addr)->sin_addr)]; } cur = cur->ifa_next; } freeifaddrs(addrs); } return nil; }// get the host name+ (NSString *)hostname{ char tempHostName[256]; int success = gethostname(tempHostName, 255); if (success != 0) return nil; tempHostName[255] = '\0'; #if TARGET_IPHONE_SIMULATOR return [NSString stringWithFormat:@"%s", tempHostName];#else return [NSString stringWithFormat:@"%s.local", tempHostName];#endif}// get the CPU info+ (BOOL)cpuInfo:(vm_statistics_data_t *)cpuStats { mach_msg_type_number_t infoCount = HOST_CPU_LOAD_INFO_COUNT; kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)cpuStats, &infoCount); return kernReturn == KERN_SUCCESS; } // get the boot time of the device+ (NSDate *)bootTime{ size_t size = sizeof(struct timeval); struct timeval *time = malloc(sizeof(struct timeval)); if(time == NULL) return nil; int mib[2] = {CTL_KERN, KERN_BOOTTIME}; sysctl(mib, 2, time, &size, NULL, 0); NSDate *bootTm = [NSDate dateWithTimeIntervalSince1970:time->tv_sec]; free(time); return bootTm;}// returns whether the device is jailbroken or not+ (BOOL)isJailBroken{ return [CCFileUtil isFileExist:@"/Applications/Cydia.app"];}// get the device version+ (NSString *)deviceVersion{ struct utsname u; uname(&u); return [NSString stringWithUTF8String:u.machine];}#if CC_ENABLE_PRIVATE_API+ (NSString *)buildVersion{ return [[UIDevice currentDevice] buildVersion];}// get the imei string // not ok+ (NSString *)getImei{ Class cls = NSClassFromString(@"NetworkController"); return [[cls sharedInstance] IMEI];}#endif@end
可能有更新:
googlecode链接地址:http://code.google.com/p/iphone-common-codes-ccteam/source/browse/trunk/CCFC/files/CCUIDevice.m
github地址: https://github.com/cxsjabc/iphone-common-codes-ccteam/tree/master/CCFC/files/CCUIDevice.m
- iphone-common-codes-ccteam源代码 CCUIDevice.m
- iphone-common-codes-ccteam源代码 CCUIDevice.h
- iphone-common-codes-ccteam源代码 CCAddressBook.m
- iphone-common-codes-ccteam源代码 CCAutoDisappearView.m
- iphone-common-codes-ccteam源代码 CCBaseTipView.m
- iphone-common-codes-ccteam源代码 CCCALayer.m
- iphone-common-codes-ccteam源代码 CCCamera.m
- iphone-common-codes-ccteam源代码 CCCommon.m
- iphone-common-codes-ccteam源代码 CCCompile.m
- iphone-common-codes-ccteam源代码 CCConfig.m
- iphone-common-codes-ccteam源代码 CCContact.m
- iphone-common-codes-ccteam源代码 CCDelete.m
- iphone-common-codes-ccteam源代码 CCDepend.m
- iphone-common-codes-ccteam源代码 CCDylib.m
- iphone-common-codes-ccteam源代码 CCEmoji.m
- iphone-common-codes-ccteam源代码 CCEncoding.m
- iphone-common-codes-ccteam源代码 CCFile.m
- iphone-common-codes-ccteam源代码 CCFileName.m
- 提取数字、提取英文、提取中文、过滤重复字符等SQL函数(含判断字段值是否有中文)
- Android Intent 用法集合
- 《Web Security Testing Cookbook》学习笔记
- iphone-common-codes-ccteam源代码 CCUIDevice.h
- 难受
- iphone-common-codes-ccteam源代码 CCUIDevice.m
- suse下编写的小程序执行
- iphone-common-codes-ccteam源代码 CCUIFont.h
- uudecode
- 快排
- iphone-common-codes-ccteam源代码 CCUIFont.m
- 研一上学期总结:迷茫探索期
- 如何在Windows下搭建Android开发环境
- MySQL 定时器EVENT学习