Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6155303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:24:48+00:00 2026-05-23T20:24:48+00:00

I need to know where my users are from, so I made a little

  • 0

I need to know where my users are from, so I made a little singleton object which gets the coordinates and uses mapkit to get the country code I need.

Here’s my header file:

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

#define TW_GEO_CODER_CHANGED_STATE  @"TW_GEO_CODER_CHANGED_STATE"

@interface TWGeoCoder : NSObject <CLLocationManagerDelegate, MKReverseGeocoderDelegate>
{
    CLLocationManager *locationManager;
    MKReverseGeocoder *geoCoder;

    NSString *currentCountryIsoCode;
}

+ (TWGeoCoder*) sharedTWGeoCoder;

-(void) startGeoCoder;
-(void) stopGeoCoder;


@property (nonatomic, retain) NSString *currentCountryIsoCode;

@end

And the implementation:

#import "TWGeoCoder.h"

@implementation TWGeoCoder


static TWGeoCoder* _singleton;

+ (TWGeoCoder*) sharedTWGeoCoder
{
    @synchronized([TWGeoCoder class])
    {
        if (_singleton == nil)
        {
            _singleton = [[TWGeoCoder alloc] init];
        }
    }
    return _singleton;
}


- (void)startGeoCoder
{  
    if (locationManager == nil) 
    {
        locationManager = [[CLLocationManager alloc] init];
    }
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.purpose = NSLocalizedString(@"#LocalizationPurpose",nil);
    [locationManager startUpdatingLocation];
}

- (void) stopGeoCoder 
{            
    if (geoCoder != nil)
    {
        [geoCoder cancel];
        [geoCoder release];
        geoCoder = nil;
    }

    if (locationManager != nil)
    {
        [locationManager stopUpdatingLocation];
        [locationManager release];
        locationManager = nil;
    }
}


#pragma mark -
#pragma mark locationManager Delegate 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{
    if (geoCoder == nil)
    {
        geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
    }

    geoCoder.delegate = self;
    [geoCoder start];       
}


- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{
    NSLog(@"locationManager:%@ didFailWithError:%@", manager, error);
    [self stopGeoCoder];
}



#pragma mark -
#pragma mark reverseGeocoder Delegate 

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{

    self.currentCountryIsoCode = placemark.countryCode;

    [[NSNotificationCenter defaultCenter] postNotificationName:TW_GEO_CODER_CHANGED_STATE 
                                                        object:self];
}


- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
    NSLog(@"reverseGeocoder:%@ didFailWithError:%@", geocoder, error);
    [self stopGeoCoder];    
}


#pragma mark -
#pragma mark Synthesizes

@synthesize currentCountryIsoCode;

@end

Well, calling stopGeoCoder method makes my app crash, even calling it via performSelectorOnMainThread…

The problem is in these lines:

if (geoCoder != nil)
    {
        [geoCoder cancel];
        [geoCoder release];
        geoCoder = nil;
    }

It seems like MKReverseGeocoder become really angry when I try to release it!
I get the crash only on the “didFail” method.
Actually, when it finds the placemark, another class will get the notification, does something and call stopGeocoder and… it doesn’t crash!
WTF?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:24:50+00:00Added an answer on May 23, 2026 at 8:24 pm

    you should refer to another post in stack overflow with the solution:

    cllocation and mkreversegeocoder

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to know which views does a user have which privileges on. I'm
Need to know which event triggered after text selection done in Apple iPad. It
I need to know the selected node's depth from a ASP.NET Treeview on client
I need to know what is the best practice for sending emails from my
I need to know if the user has hidden an icon added by my
I need to know the ID of the current user in a model: def
I need to know when a WPF Datagrid has been sorted by the user.
Need to know this so that i could send DTMF and that is going
I need to know if all the client-side validator checks have succeeded, or if
i need to know how can i connect telephone using php languages

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.