iOS獲取設(shè)備各種硬件信息

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;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市灵疮,隨后出現(xiàn)的幾起案子织阅,更是在濱河造成了極大的恐慌,老刑警劉巖震捣,帶你破解...
    沈念sama閱讀 206,311評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件荔棉,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡蒿赢,警方通過查閱死者的電腦和手機(jī)润樱,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,339評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來羡棵,“玉大人壹若,你說我怎么就攤上這事≡肀” “怎么了舌稀?”我有些...
    開封第一講書人閱讀 152,671評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵,是天一觀的道長灼擂。 經(jīng)常有香客問我,道長觉至,這世上最難降的妖魔是什么剔应? 我笑而不...
    開封第一講書人閱讀 55,252評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮语御,結(jié)果婚禮上峻贮,老公的妹妹穿的比我還像新娘。我一直安慰自己应闯,他們只是感情好纤控,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,253評(píng)論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著碉纺,像睡著了一般船万。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上骨田,一...
    開封第一講書人閱讀 49,031評(píng)論 1 285
  • 那天耿导,我揣著相機(jī)與錄音,去河邊找鬼态贤。 笑死舱呻,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的悠汽。 我是一名探鬼主播箱吕,決...
    沈念sama閱讀 38,340評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼芥驳,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了茬高?” 一聲冷哼從身側(cè)響起兆旬,我...
    開封第一講書人閱讀 36,973評(píng)論 0 259
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎雅采,沒想到半個(gè)月后爵憎,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,466評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡婚瓜,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,937評(píng)論 2 323
  • 正文 我和宋清朗相戀三年宝鼓,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片巴刻。...
    茶點(diǎn)故事閱讀 38,039評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡愚铡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出胡陪,到底是詐尸還是另有隱情沥寥,我是刑警寧澤,帶...
    沈念sama閱讀 33,701評(píng)論 4 323
  • 正文 年R本政府宣布柠座,位于F島的核電站邑雅,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏妈经。R本人自食惡果不足惜淮野,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,254評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望吹泡。 院中可真熱鬧骤星,春花似錦、人聲如沸爆哑。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,259評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽揭朝。三九已至队贱,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間潭袱,已是汗流浹背露筒。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評(píng)論 1 262
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留敌卓,地道東北人慎式。 一個(gè)月前我還...
    沈念sama閱讀 45,497評(píng)論 2 354
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親瘪吏。 傳聞我的和親對(duì)象是個(gè)殘疾皇子癣防,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,786評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容