您的位置:首页 > 理论基础 > 计算机网络

IOS模拟器能获取运营商信息,网络连接类型以及地理位置吗?

2016-12-30 00:47 507 查看
代码如下:

//获取运营商信息和网络连接类型

-(void)getCarrierInfoAndConnectType

{

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

    CTCarrier* carrier = [info subscriberCellularProvider];

    if (carrier != NULL)

    {

        mCarrier = [carrier carrierName];

        mConnectType = [carrier mobileNetworkCode];

    }

    NSLog(@"carrier:%@",mCarrier);

    NSLog(@"connectype:%@",mConnectType);

}

//获取地理位置

- (void) getPosInfo

{

    CLLocationManager* locationManager = [[CLLocationManager alloc] init];

    if(![locationManager locationServicesEnabled])

    {

        NSLog(@"请打开定位服务");

        return ;

    }

    locationManager.delegate = self;

    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    locationManager.distanceFilter = kCLDistanceFilterNone;

    [locationManager startUpdatingLocation];

}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

{

    NSLog(@"获取地理位置开始");

    CLLocation* currentLocation = [locations lastObject];

    

    CLLocationCoordinate2D coor = currentLocation.coordinate;

    mUserPos =[[NSString alloc] initWithFormat:@"latitude=%g&longitude=%g",coor.latitude,coor.longitude];

    

     NSLog(@"userpos:%@",mUserPos);

}

//******************

上述代码得到的运营商信息,网络连接类型,地理位置都是空,要怎么获取?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: