iOS iOS各種裝置資訊獲取

2022-03-17 22:50:04 字數 3371 閱讀 3867

這個方法後面會列出來

nsstring *devicename =[self getdevicename];

nslog(

@"裝置型號-->%@

", devicename);

nsstring *iphonename =[uidevice currentdevice].name;

nslog(

@"iphone名稱-->%@

", iphonename);

cfbundleshortversionstring"];

nslog(@""

cgfloat batterylevel =[[uidevice currentdevice] batterylevel];

nslog(

@"電池電量-->%f

", batterylevel);

nsstring *localizedmodel =[uidevice currentdevice].localizedmodel;

nslog(

@"localizedmodel-->%@

", localizedmodel);

nsstring *systemname =[uidevice currentdevice].systemname;

nslog(

@"當前系統名稱-->%@

", systemname);

nsstring *systemversion =[uidevice currentdevice].systemversion;

nslog(

@"當前系統版本號-->%@

", systemversion);

struct

utsname systeminfo;

uname(&systeminfo);

nsstring *device_model =[nsstring stringwithcstring:systeminfo.machine encoding:nsutf8stringencoding];

nslog(

@"device_model-->%@

", device_model);

//這個方法後面會單獨列出

nsstring *macaddress =[self getmacaddress];

nslog(

@"macaddress-->%@

", macaddress);

//這個方法後面會單獨列出

nsstring *deviceip =[self getdeviceipaddresses];

nslog(

@"deviceip-->%@

", deviceip);

//

廣告標識

nsstring *idfa =[[[asidentifiermanager sharedmanager] advertisingidentifier] uuidstring];

nslog(

@"廣告位識別符號idfa-->%@

", idfa);

//

uuid

nsstring *uuid =[[[uidevice currentdevice] identifierforvendor] uuidstring];

nslog(

@"唯一識別碼uuid-->%@

", uuid);

//

獲取裝置型號然後手動轉化為對應名稱

- (nsstring *)getdevicename

- (nsstring *)getmacaddress 

if (sysctl(mib, 6, null, &len, null, 0) < 0

)

if ((buf = malloc(len)) ==null)

if (sysctl(mib, 6, buf, &len, null, 0) < 0

) ifm = (struct if_msghdr *)buf;

sdl = (struct sockaddr_dl *)(ifm + 1

); ptr = (unsigned char *)lladdr(sdl);

nsstring *outstring = [nsstring stringwithformat:@"

%02x%02x%02x%02x%02x%02x

", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5

)]; free(buf);

return

[outstring uppercasestring];

}

- (nsstring *)getdeviceipaddresses 

ptr += sizeof(ifr->ifr_name) +len;

if (ifr->ifr_addr.sa_family != af_inet) continue

;

if ((cptr = (char *)strchr(ifr->ifr_name, '

:')) != null) *cptr = 0

;

if (strncmp(lastname, ifr->ifr_name, ifnamsiz) == 0) continue

; memcpy(lastname, ifr->ifr_name, ifnamsiz);

ifrcopy = *ifr;

ioctl(sockfd, siocgifflags, &ifrcopy);

if ((ifrcopy.ifr_flags & iff_up) == 0) continue

; nsstring *ip = [nsstring stringwithformat:@"

%s", inet_ntoa(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr)];

[ips addobject:ip];}}

close(sockfd);

nsstring *deviceip = @""

;

for (int i=0; i < ips.count; i++)

}return

deviceip;

}

iOS各種裝置資訊獲取總結

這個方法後面會列出來 nsstring devicename self getdevicename nslog 裝置型號 devicename nsstring iphonename uidevice currentdevice name nslog iphone名稱 iphonename cgfl...

史上最全的iOS各種裝置資訊獲取總結

github 這個方法後面會列出來 nsstring devicename selfgetdevicename nslog 裝置型號 devicename nsstring iphonename uidevicecurrentdevice name nslog iphone名稱 iphonename...

獲取iOS裝置資訊

鑌哥就直接寫 了 獲取手機資訊 應用程式的名稱和版本號等資訊都儲存在mainbundle的乙個字典中,用下面 可以取出來 nsdictionary infodict nsbundle mainbundle infodictionary nsstring versionnum infodict obj...