最近項目需要檢測設(shè)備的信號值,舊設(shè)備很多方法可用就不一一贅述,只是記錄下自己的學(xué)習(xí)歷程,
首先判斷設(shè)備型號代碼如下
//機型判斷
struct utsname systemInfo;
uname(&systemInfo);
NSString * platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
UIApplication * appll = [UIApplication sharedApplication];
id oneOc = [appll valueForKeyPath:@"_statusBar"];
id twoOc = [oneOc valueForKeyPath:@"_statusBar"];
遍歷頂部狀態(tài)欄,通過斷點調(diào)試發(fā)現(xiàn)x以后頂部狀態(tài)欄是由以下變化的如圖:
image.png
找到 _cellularEntry 就好辦了
id twoOc1 = [twoOc valueForKeyPath:@"_currentData"];
id ocStr = [[twoOc1 valueForKey:@"_cellularEntry"]valueForKeyPath:@"_displayValue"];
至此,獲取設(shè)備的信號量的值.