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

来源:互联网 发布:java分布式架构概念 编辑:程序博客网 时间:2024/05/21 17:27
代码如下:
//获取运营商信息和网络连接类型
-(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);
}

//******************
上述代码得到的运营商信息,网络连接类型,地理位置都是空,要怎么获取?

0 0