CoreTelephony运营商信息

CoreTelephony是苹果提供的用来访问用户的移动服务提供商的信息,比如它的唯一标识符,以及是否允许VoIP通话。获取当前通过的id以及状态。

CoreTelephony在iOS7之前是私有API,在iOS7之后苹果公开了CoreTelephony。 

https://developer.apple.com/reference/coretelephony


1.可以用CoreTelephony获取手机运营商的信息。

- (void)getcarrierName

{

    CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];

    CTCarrier *carrier = [telephonyInfo subscriberCellularProvider];

    NSString *currentCountry = [carrier carrierName];   // 运营商名字

    NSLog(@"[carrier isoCountryCode]==%@,[carrier allowsVOIP]=%d,[carrier mobileCountryCode=%@,[carrier mobileCountryCode]=%@",[carrier isoCountryCode],[carrier allowsVOIP],[carrier mobileCountryCode],[carrier mobileNetworkCode]);

}


2.可以用CoreTelephony监控通话信息。

CTCallCenter *center = [[CTCallCenter alloc] init];

center.callEventHandler = ^(CTCall *call) {

    NSString *callState = call.callState;

    NSString *callID = call.callID;

};


3.号外:获取当前使用网络的运营商的信息。

- (void)networkMobile

{

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    manager.responseSerializer = [AFJSONResponseSerializer serializer];

    manager.requestSerializer = [AFJSONRequestSerializer serializer];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];

    

    [manager GET:@"http://g3.letv.cn/recommend?format=1" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {

            NSLog(@"%@ >> %@", responseObject, responseObject[@"desc"]);

        }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        

    }];

}




你可能感兴趣的:(iOS)