日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS开发之获取运营商和WIFI

發布時間:2024/5/8 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS开发之获取运营商和WIFI 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下面是我們常用的一些獲取手機信息的方法,大家可以看看。

不過在目前的版本里面,很多手機信息已經獲取不到了,因為蘋果在這方面的保密性做得越來越嚴格。

IMEI,IMSI,DeviceID,手機號碼等我們都已經獲取不到了,下面一些我們可能獲取到的,也可能因為是私有API而導致審核被拒,大家在借鑒的時候要慎重。

/// @brief 獲取連接方式

+ (NSString *)getConfiguration{

? ? // 狀態欄是由當前app控制的,首先獲取當前app

? ? UIApplication *app = [UIApplication sharedApplication];

? ? NSArray *children = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];

? ? int type = 0;

? ? for (id child in children) {

?? ? ? ? ? if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {

? ? ? ? ? ? ? ? type = [[child valueForKeyPath:@"dataNetworkType"] intValue];

? ? ? ? ? ? }

? ? }

?? ?

? ? switch (type) {

? ? ? ? case 0:return @"無網絡";break;

? ? ? ? ? ? case 1:return @"2G";break;

? ? ? ? ? ? case 2:return @"3G";break;

? ? ? ? ? ? case 3:return @"4G";break;

? ? ? ? ? ? case 5:return @"WIFI";break;

?? ? ? ? ? ?

? ? ? ? default:return @"無網絡";

? ? ? ? ? ? break;

? ? }

}


/// @brief 獲取運營商信息 可能會被封殺

+ (NSString *)getCarrier {

? ? CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];

? ? CTCarrier *carrier = [info subscriberCellularProvider];

? ? return [NSString stringWithFormat:@"%@",[carrier carrierName]];

}


/// @brief 獲取當前wifi名稱

+ (NSString *)getSSID {

? ? NSString *ssid = nil;

? ? NSArray *ifs = (__bridge ? id)CNCopySupportedInterfaces();

? ? for (NSString *ifname in ifs) {

? ? ? ? NSDictionary *info = (__bridge id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifname);

? ? ? ? if (info[@"SSID"])

? ? ? ? {

? ? ? ? ? ? ssid = info[@"SSID"];

? ? ? ? }

? ? }

? ? return ssid;

}


/// @brief 獲取bssid

+ (NSString *)getbSSID {

? ? NSString *bssid = nil;

? ? NSArray *ifs = (__bridge ? id)CNCopySupportedInterfaces();

? ? for (NSString *ifname in ifs) {

? ? ? ? NSDictionary *info = (__bridge id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifname);

? ? ? ? if (info[@"BSSID"])

? ? ? ? {

? ? ? ? ? ? bssid = info[@"BSSID"];

? ? ? ? }

? ? }

? ? return bssid;

}


//獲取ip地址

+ (NSString *)getIpAddresses{

? ? 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;

}



總結

以上是生活随笔為你收集整理的iOS开发之获取运营商和WIFI的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。