Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Find the country of the user

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 309
    Comment on it

    To find out the country of the user please use the code below:
    1- Add the coreLocation Framework to your project and import #import <corelocation corelocation.h="">
    2- Set the CLLocationManagerDelegate as UIViewController

    @interface LocationViewController : UIViewController<CLLocationManagerDelegate>
        {
            CLLocationManager *locationManager;
           CLGeocoder *geocoder;
            CLPlacemark *placemark;
        }
    

    3- And in LocationViewController.m file use the code below.

    - (void)viewDidLoad {
    
        locationManager = [[CLLocationManager alloc] init];
    
        locationManager.delegate = self;
    
        if([[[UIDevice currentDevice]systemVersion] floatValue]>=8.0?YES:NO)
        {
            [locationManager requestAlwaysAuthorization];
    
        }
    
        geocoder = [[CLGeocoder alloc] init];
        locationManager.distanceFilter = kCLDistanceFilterNone; 
        locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; 
    
        [locationManager startUpdatingLocation];
    }
    
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
    
        CLLocation *currentLocation = newLocation;
    
        if (currentLocation != nil) {
    
    
            [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
    
                if (error == nil && [placemarks count] > 0) {
                    placemark = [placemarks lastObject];
                    NSLog(@"user contry==%@",placemark.country);
    
    
                } else {
                    NSLog(@"%@", error.debugDescription);
                }
            } ];
        }
    
        [locationManager stopUpdatingLocation];
    
    
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: