国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS 獲取本地設備IP地址

2019-11-09 17:04:42
字體:
來源:轉載
供稿:網友
#import <ifaddrs.h>#import <arpa/inet.h>// Get ip Address- (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;}

1.已禁用-[UIDevice uniqueIdentifier]

  蘋果總是把用戶的隱私看的很重要。-[UIDevice uniqueIdentifier]在iOS5實際在iOS5的時候已經被遺棄了,但是iOS7中已經完全的禁用了它。Xcode5甚至不會允許你編譯包含了指引到-[UIDevice uniqueIdentifier]的app。此外,iOS7之前的使用了-[UIDevice uniqueIdentifier] 的app如果在iOS7上運行,它不會返回設備的UUID,而是會返回一串字符串,以FFFFFFFF開頭,跟著-[UIDevice identifierForVendor]的十六進制值。

現在蘋果明確的表明你應該使用-[UIDevice identifierForVendor]或是-[ASIdentifierManager advertisingIdentifier]來作為你框架和應用的唯一標示符。坦白的來說,應對這些變化也不是那么的難,見以下代碼片段:

NSString *identifierForVendor = [[UIDevice currentDevice].identifierForVendor UUIDString]; NSString *identifierForAdvertising = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString]; 

每種方法都適配一種特別的用法:

  identifierForVendor對供應商來說是唯一的一個值,也就是說,由同一個公司發行的的app在相同的設備上運行的時候都會有這個相同的標識符。然而,如果用戶刪除了這個供應商的app然后再重新安裝的話,這個標識符就會不一致。

  advertisingIdentifier會返回給在這個設備上所有軟件供應商相同的 一個值,所以只能在廣告的時候使用。這個值會因為很多情況而有所變化,比如說用戶初始化設備的時候便會改變。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海盐县| 崇左市| 景东| 靖州| 忻城县| 德保县| 赣榆县| 颍上县| 南木林县| 门头沟区| 梁平县| 金阳县| 潍坊市| 石阡县| 岱山县| 集安市| 图木舒克市| 和平县| 河池市| 溆浦县| 奉化市| 巴中市| 留坝县| 滨州市| 镶黄旗| 南平市| 保德县| 南部县| 简阳市| 会理县| 唐山市| 万载县| 高清| 石嘴山市| 兴业县| 文昌市| 南充市| 庄河市| 巫山县| 五家渠市| 航空|