1.NSLog(@"%@",[[UIDevice currentDevice] systemVersion]);//系統(tǒng)版本
2.獲取手機(jī)型號(hào) 需要頭文件 #import <sys/utsname.h>
- (NSString *)iphoneType {
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4";
if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4";
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c";
if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c";
if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s";
if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s";
if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhone SE";
if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone 7";
if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone 7 Plus";
if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
if ([platform isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G";
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad 1G";
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2";
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2";
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2";
if ([platform isEqualToString:@"iPad2,4"]) return @"iPad 2";
if ([platform isEqualToString:@"iPad2,5"]) return @"iPad Mini 1G";
if ([platform isEqualToString:@"iPad2,6"]) return @"iPad Mini 1G";
if ([platform isEqualToString:@"iPad2,7"]) return @"iPad Mini 1G";
if ([platform isEqualToString:@"iPad3,1"]) return @"iPad 3";
if ([platform isEqualToString:@"iPad3,2"]) return @"iPad 3";
if ([platform isEqualToString:@"iPad3,3"]) return @"iPad 3";
if ([platform isEqualToString:@"iPad3,4"]) return @"iPad 4";
if ([platform isEqualToString:@"iPad3,5"]) return @"iPad 4";
if ([platform isEqualToString:@"iPad3,6"]) return @"iPad 4";
if ([platform isEqualToString:@"iPad4,1"]) return @"iPad Air";
if ([platform isEqualToString:@"iPad4,2"]) return @"iPad Air";
if ([platform isEqualToString:@"iPad4,3"]) return @"iPad Air";
if ([platform isEqualToString:@"iPad4,4"]) return @"iPad Mini 2G";
if ([platform isEqualToString:@"iPad4,5"]) return @"iPad Mini 2G";
if ([platform isEqualToString:@"iPad4,6"]) return @"iPad Mini 2G";
if ([platform isEqualToString:@"i386"]) return @"iPhone Simulator";
if ([platform isEqualToString:@"x86_64"]) return @"iPhone Simulator";
return platform;
}
3.NSString *identifierStr = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSLog(@"設(shè)備唯一標(biāo)識(shí)符:%@",identifierStr);
4.[UIDevice currentDevice].batteryMonitoringEnabled = YES;?
double deviceLevel = [UIDevice currentDevice].batteryLevel;
獲取當(dāng)前剩余電量, 我們通常采用上述方法即蘋果官方文檔提供的攒霹。
它返回的是0.00-1.00之間的浮點(diǎn)值。? 另外, -1.00表示模擬器。
但是仔細(xì)觀察它的返回值, ?是以0.05遞變的蛛芥。 折算成100% 也就是以5%來遞變的纱烘。
也就是說,很不精確曲楚。
下面方法幢痘。相當(dāng)精確, 誤差保持在1%以內(nèi)裂七。
我們知道, Mac下有個(gè)IOKit.framework庫皆看。 它可以計(jì)算出我們需要的電量。
如果我們要使用它的話, (iOS是不提供的) 可以先建立一個(gè)Mac下的工程, 找到IOKit.framework背零,那IOKit.framework里面的IOPowerSources.h和IOPSKeys.h拷貝到你的iOS項(xiàng)目中腰吟。另外, 還需要把IOKit也導(dǎo)入到你的工程中去。(請(qǐng)使用真機(jī)調(diào)試)
- (NSString*)batteryLevel
{
CFTypeRef blob = IOPSCopyPowerSourcesInfo();
CFArrayRef sources = IOPSCopyPowerSourcesList(blob);
CFDictionaryRef pSource = NULL;
const void *psValue;
int numOfSources = CFArrayGetCount(sources);
if (numOfSources == 0)
{
CFRelease(blob);
CFRelease(sources);
NSLog(@"qhk: Error in CFArrayGetCount");
return nil;
}
for (int i = 0 ;i < numOfSources ; i++)
{
pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, i));
if (!pSource)
{
CFRelease(blob);
CFRelease(sources);
NSLog(@"qhk: Error in IOPSGetPowerSourceDescription");
return nil;
}
psValue = (CFStringRef)CFDictionaryGetValue(pSource, CFSTR(kIOPSNameKey));
int curCapacity = 0;
int maxCapacity = 0;
//? ? ? ? ? ? ? ? double percent;
psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSCurrentCapacityKey));
CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &curCapacity);
psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSMaxCapacityKey));
CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &maxCapacity);
//? ? ? ? ? ? ? ? percent = ((double)curCapacity/(double)maxCapacity * 100.0f);
NSNumber* no1 = [NSNumber numberWithInt:curCapacity];
NSNumber* no2= [NSNumber numberWithInt:maxCapacity];
CFRelease(blob);
CFRelease(sources);
return [NSDictionary dictionaryWithObjectsAndKeys:no1, @"no1", no2, @"no2", nil];
//? ? ? ? ? ? ? ? return percent;
//? ? ? ? ? ? ? ? return (NSInteger)(percent + 0.5f);
}
//#endif
CFRelease(blob);
CFRelease(sources);
return nil;
}
5.#pragma mark 獲取ip地址 頭文件 #include <ifaddrs.h> #include <sys/socket.h> #include <arpa/inet.h>
- (NSString *)getIPAddress{
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0) {
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL) {
if(temp_addr->ifa_addr->sa_family == AF_INET) {
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
return address;
}
6.#pragma mark? 內(nèi)存使用狀況? 頭文件 #import <mach/mach.h>
//獲取總內(nèi)存大小 (單位:MB)
-(double)getTotalMemorySize
{
? return [NSProcessInfo processInfo].physicalMemory/1024/1024;
}
// 獲取當(dāng)前設(shè)備可用內(nèi)存(單位:MB)
- (double)availableMemory
{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(),
HOST_VM_INFO,
(host_info_t)&vmStats,
&infoCount);
if (kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size *vmStats.free_count) / 1024.0) / 1024.0;
}
7.#pragma mark ?獲取當(dāng)前任務(wù)所占用的內(nèi)存(單位:MB) ?頭文件 #import <mach/mach.h>
- (double)usedMemory
{
task_basic_info_data_t taskInfo;
mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
kern_return_t kernReturn = task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&taskInfo,
&infoCount);
if (kernReturn != KERN_SUCCESS
) {
return NSNotFound;
}
return taskInfo.resident_size / 1024.0 / 1024.0;
}
8.//NSFileManager包含非常豐富的信息,通過下面的方法可很容易的獲取系統(tǒng)磁盤的大小和可用磁盤的大小
#pragma mark 總的磁盤空間
- (float)getTotalDiskspace{
float totalSpace;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
totalSpace = [fileSystemSizeInBytes floatValue]/1024.0f/1024.0f/1024.0f;
} else {
totalSpace = 0;
}
return totalSpace;
}
#pragma mark 可用磁盤空間
- (float)getFreeDiskspace{
float freeSpace;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
freeSpace = [freeFileSystemSizeInBytes floatValue]/1024.0f/1024.0f/1024.0f;
} else {
freeSpace = 0;
}
return freeSpace;
}
9.獲取網(wǎng)絡(luò)類型(AFNetWorking)
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown: {
[Const warningTitle:@"未知網(wǎng)絡(luò)"];
break;
}
case AFNetworkReachabilityStatusNotReachable: {
[Const warningTitle:@"無連接"];
break;
}
case AFNetworkReachabilityStatusReachableViaWWAN: {
[Const warningTitle:@"當(dāng)前為移動(dòng)流量"];
break;
}
case AFNetworkReachabilityStatusReachableViaWiFi: {
[Const warningTitle:@"當(dāng)前鏈接wifi"];
break;
}
default: {
break;
}
}
}];
[manager startMonitoring];
10.獲取當(dāng)前APP的cpu占用 頭文件 #import <mach/mach.h>
//app的cpu占用
- (float)cpu_usage
{
kern_return_t kr = { 0 };
task_info_data_t tinfo = { 0 };
mach_msg_type_number_t task_info_count = TASK_INFO_MAX;
kr = task_info( mach_task_self(), TASK_BASIC_INFO, (task_info_t)tinfo, &task_info_count );
if ( KERN_SUCCESS != kr )
return 0.0f;
task_basic_info_t basic_info = { 0 };
thread_array_t thread_list = { 0 };
mach_msg_type_number_t thread_count = { 0 };
thread_info_data_t thinfo = { 0 };
thread_basic_info_t basic_info_th = { 0 };
basic_info = (task_basic_info_t)tinfo;
// get threads in the task
kr = task_threads( mach_task_self(), &thread_list, &thread_count );
if ( KERN_SUCCESS != kr )
return 0.0f;
long tot_sec = 0;
long tot_usec = 0;
float tot_cpu = 0;
for ( int i = 0; i < thread_count; i++ )
{
mach_msg_type_number_t thread_info_count = THREAD_INFO_MAX;
kr = thread_info( thread_list[i], THREAD_BASIC_INFO, (thread_info_t)thinfo, &thread_info_count );
if ( KERN_SUCCESS != kr )
return 0.0f;
basic_info_th = (thread_basic_info_t)thinfo;
if ( 0 == (basic_info_th->flags & TH_FLAGS_IDLE) )
{
tot_sec = tot_sec + basic_info_th->user_time.seconds + basic_info_th->system_time.seconds;
tot_usec = tot_usec + basic_info_th->system_time.microseconds + basic_info_th->system_time.microseconds;
tot_cpu = tot_cpu + basic_info_th->cpu_usage / (float)TH_USAGE_SCALE;
}
}
kr = vm_deallocate( mach_task_self(), (vm_offset_t)thread_list, thread_count * sizeof(thread_t) );
if ( KERN_SUCCESS != kr )
return 0.0f;
return tot_cpu;
}
11.獲取手機(jī)運(yùn)行時(shí)長 頭文件#include <sys/sysctl.h>
//獲取手機(jī)運(yùn)行時(shí)長 單位秒
-(time_t)timeRun
{
struct timeval boottime;
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
size_t size = sizeof(boottime);
time_t now;
time_t uptime = -1;
(void)time(&now);
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0)
{
uptime = now - boottime.tv_sec;
}
return uptime;
}
- (void )timeRunDay
{
double time = (double)[self timeRun];
//Day
NSInteger timeDay = 0;
//Hour
NSInteger timeHour = 0;
//Minute
NSInteger timeMinute = 0;
//Second
NSInteger timeSecond = 0;
if (time>=60*60*24) {
timeDay = (NSInteger)time/60/60/24;
}
if (time>60*60) {
timeHour = (NSInteger)time%(60*60*24)/(60*60);
}
if (time>60) {
timeMinute = (NSInteger)time%(60*60*24)%(60*60)/60;
}
timeSecond = (NSInteger)time%(60*60*24)%(60*60)%60;
NSLog(@"此設(shè)備已經(jīng)運(yùn)行 %ld天 %ld時(shí) %ld分 %ld秒",(long)timeDay,(long)timeHour,(long)timeMinute,(long)timeSecond);
}
//根據(jù)運(yùn)行時(shí)長計(jì)算開機(jī)時(shí)間
- (NSString *)bootTime
{
double time = (double)[self timeRun];
//Day
NSInteger timeDay = 0;
//Hour
NSInteger timeHour = 0;
//Minute
NSInteger timeMinute = 0;
//Second
NSInteger timeSecond = 0;
if (time>=60*60*24) {
timeDay = (NSInteger)time/60/60/24;
}
if (time>60*60) {
timeHour = (NSInteger)time%(60*60*24)/(60*60);
}
if (time>60) {
timeMinute = (NSInteger)time%(60*60*24)%(60*60)/60;
}
timeSecond = (NSInteger)time%(60*60*24)%(60*60)%60;
//得到當(dāng)前的時(shí)間
NSDate * mydate = [NSDate date];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"---當(dāng)前的時(shí)間的字符串 =%@",currentDateStr);
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *comps = nil;
comps = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitMonth fromDate:mydate];
NSDateComponents *adcomps = [[NSDateComponents alloc] init];
[adcomps setDay:-timeDay];//當(dāng)前時(shí)間幾天前
[adcomps setHour:-timeHour];
[adcomps setMinute:-timeMinute];
[adcomps setSecond:-timeSecond];
NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:mydate options:0];
NSString *beforDate = [dateFormatter stringFromDate:newdate];
NSLog(@"---開機(jī)時(shí)間 =%@",beforDate);
return beforDate;
}
12.獲取開機(jī)時(shí)間算起設(shè)備消耗流量 頭文件 #include <ifaddrs.h> #include <sys/socket.h> #include <net/if.h>
-(NSDictionary *)DataCounters
{
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
u_int32_t WiFiSent = 0;
u_int32_t WiFiReceived = 0;
u_int32_t WWANSent = 0;
u_int32_t WWANReceived = 0;
if (getifaddrs(&addrs) == 0)
{
cursor = addrs;
while (cursor != NULL)
{
if (cursor->ifa_addr->sa_family == AF_LINK)
{
#ifdef DEBUG
const struct if_data *ifa_data = (struct if_data *)cursor->ifa_data;
if(ifa_data != NULL)
{
NSLog(@"Interface name %s: sent %tu received %tu",cursor->ifa_name,ifa_data->ifi_obytes,ifa_data->ifi_ibytes);
}
#endif
// name of interfaces:
// en0 is WiFi
// pdp_ip0 is WWAN
NSString *name = [NSString stringWithFormat:@"%s",cursor->ifa_name];
if ([name hasPrefix:@"en"])
{
const struct if_data *ifa_data = (struct if_data *)cursor->ifa_data;
if(ifa_data != NULL)
{
WiFiSent += ifa_data->ifi_obytes;
WiFiReceived += ifa_data->ifi_ibytes;
}
}
if ([name hasPrefix:@"pdp_ip"])
{
const struct if_data *ifa_data = (struct if_data *)cursor->ifa_data;
if(ifa_data != NULL)
{
WWANSent += ifa_data->ifi_obytes;
WWANReceived += ifa_data->ifi_ibytes;
}
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
NSString *stringsdsdsd = [NSString stringWithFormat:@"wifi 發(fā)送:%.2f wifi 收到:%.2f MBn 2g/3g/4g 發(fā)送 :%.2f MBn 2g/3g/4g 收到:%.2f MBn",WiFiSent/1024.0/1024.0,WiFiReceived/1024.0/1024.0,WWANSent/1024.0/1024.0,WWANReceived/1024.0/1024.0];
label2.text = stringsdsdsd;
return @{DataCounterKeyWiFiSent:[NSNumber numberWithUnsignedInt:WiFiSent],
DataCounterKeyWiFiReceived:[NSNumber numberWithUnsignedInt:WiFiReceived],
DataCounterKeyWWANSent:[NSNumber numberWithUnsignedInt:WWANSent],
DataCounterKeyWWANReceived:[NSNumber numberWithUnsignedInt:WWANReceived]};
}
13.獲取子網(wǎng)掩碼毛雇,廣播地址及IP 頭文件 #include <sys/socket.h> #import <arpa/inet.h> #import <ifaddrs.h> #include <netdb.h> #import "getgateway.h"
#pragma mark - 獲取路由器地址
- (NSString *) routerIp {
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0)
{
// Loop through linked list of interfaces
temp_addr = interfaces;
//*/
while(temp_addr != NULL)
/*/
int i=255;
while((i--)>0)
//*/
{
if(temp_addr->ifa_addr->sa_family == AF_INET)
{
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
{
// Get NSString from C String //ifa_addr
//ifa->ifa_dstaddr is the broadcast address, which explains the "255's"
//? ? ? ? ? ? ? ? ? ? address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_dstaddr)->sin_addr)];
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
//routerIP----192.168.1.255 廣播地址
NSLog(@"broadcast address--%@",[NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_dstaddr)->sin_addr)]);
//--192.168.1.106 本機(jī)地址
NSLog(@"local device ip--%@",[NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]);
//--255.255.255.0 子網(wǎng)掩碼地址
NSLog(@"netmask--%@",[NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_netmask)->sin_addr)]);
//--en0 端口地址
NSLog(@"interface--%@",[NSString stringWithUTF8String:temp_addr->ifa_name]);
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
in_addr_t i =inet_addr([address cStringUsingEncoding:NSUTF8StringEncoding]);
in_addr_t* x =&i;
unsigned char *s = getdefaultgateway(x);
NSString *ip=[NSString stringWithFormat:@"%d.%d.%d.%d",s[0],s[1],s[2],s[3]];
free(s);
return ip;
}
14.//獲取sim卡信息 倒入SystemConfiguration和CoreTelephony嫉称。頭文件 #import <SystemConfiguration/CaptiveNetwork.h> #import <CoreTelephony/CTTelephonyNetworkInfo.h> #import <CoreTelephony/CTCarrier.h>
- (void)simMessage
{
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = networkInfo.subscriberCellularProvider;
NSString *carrier_country_code = carrier.isoCountryCode;
if (carrier_country_code == nil) {
carrier_country_code = @"";
}
//國家編號(hào)
NSString *CountryCode = carrier.mobileCountryCode;
if (CountryCode == nil) {
CountryCode = @"";
}
NSLog(@"國家編號(hào) = %@",CountryCode);
//網(wǎng)絡(luò)供應(yīng)商編碼
NSString *NetworkCode = carrier.mobileNetworkCode;
if (NetworkCode == nil)
{
NetworkCode = @"";
}
NSLog(@"網(wǎng)絡(luò)供應(yīng)商編碼 = %@",NetworkCode);
NSString *mobile_country_code = [NSString stringWithFormat:@"%@%@",CountryCode,NetworkCode];
if (mobile_country_code == nil)
{
mobile_country_code = @"";
}
NSString *carrier_name = nil;? ? //網(wǎng)絡(luò)運(yùn)營商的名字
NSString *code = [carrier mobileNetworkCode];
if ([code isEqualToString:@"00"] || [code isEqualToString:@"02"] || [code isEqualToString:@"07"]) {
//移動(dòng)
carrier_name = @"CMCC";
}
if ([code isEqualToString:@"03"] || [code isEqualToString:@"05"])
{
// ret = @"電信";
carrier_name =? @"CTCC";
}
if ([code isEqualToString:@"01"] || [code isEqualToString:@"06"])
{
// ret = @"聯(lián)通";
carrier_name =? @"CUCC";
}
if (code == nil)
{
carrier_name = @"";
}
carrier_name = [[NSString stringWithFormat:@"%@-%@",carrier_name,carrier.carrierName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
15.//獲取cpu核數(shù) 頭文件 #include <sys/sysctl.h>
- (unsigned int)countofCores
{
unsigned int ncpu;
size_t len = sizeof(ncpu);
sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
return ncpu;
}