iOS各種裝置資訊獲取總結

2021-07-26 06:11:24 字數 3236 閱讀 1740

// 這個方法後面會列出來

nsstring *devicename = [self getdevicename];

nslog(@"裝置型號-->%@", devicename);

nsstring *iphonename = [uidevice currentdevice].name;

nslog(@"iphone名稱-->%@", iphonename);

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是universally unique identifier的縮寫,中文意思是通用唯一識別碼。它是讓分布式系統中的所有元素,都能有唯一的辨識資訊,而不需要透過**控制端來做辨識資訊的指 定。這樣,每個人都可以建立不與其它人衝突的 uuid。在此情況下,就不需考慮資料庫建立時的名稱重複問題。蘋果公司建議使用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各種裝置資訊獲取總結

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

獲取iOS裝置資訊

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

iOS 獲取裝置資訊

ios 獲取裝置資訊 獲取裝置資訊,不囉嗦,直接上 uidevice idfa add adsupport.framework define kdeviceidfa asidentifiermanager sharedmanager advertisingidentifier uuidstring ...