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 7406013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:29:27+00:00 2026-05-29T05:29:27+00:00

Let me qualify by saying I’m new to Objective-C/iOS. My program is crashing on

  • 0

Let me qualify by saying I’m new to Objective-C/iOS.

My program is crashing on the uncaught exception NSInvalidArgumentException, reason: [CLLocationManager copyWithZone:]: unrecognized selector sent to instance. This seems to be a pretty common error, and best I can tell, it usually happens when something’s gone wrong memory-management wise. I’ve looked at similar questions on stackoverflow and Google, but none seem quite the same.

My application is a simple single view app. I’m trying to use the CLLocationManager class, because I want to get the user’s heading. My code:

magnetoTestViewController.h

#import <UIKit/UIKit.h>
@class CLLocationManager;

@interface magnetoTestViewController : UIViewController
@property(copy, readwrite) CLLocationManager *locManager;
@end

magnetoTestViewController.m

#import "magnetoTestViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface magnetoTestViewController()
- (void)startHeadingEvents;
@end

@implementation magnetoTestViewController

@synthesize locManager = _locManager;

...

- (void)startHeadingEvents {
NSLog(@"entered startHeadingEvents()");
if (!self.locManager) {
    CLLocationManager* theManager = [[CLLocationManager alloc] init];

    // Retain the object in a property.
    self.locManager = theManager;
    self.locManager.delegate = self;
}

// Start location services to get the true heading.
self.locManager.distanceFilter = 1000;
self.locManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[self.locManager startUpdatingLocation];

// Start heading updates.
if ([CLLocationManager headingAvailable]) {
    NSLog(@"Yep, the heading is available.");
    self.locManager.headingFilter = 5;
    [self.locManager startUpdatingHeading];
}
else {
    NSLog(@"*sadface*, the heading information is not available.");
}
NSLog(@"exited startHeadingEvents()");
}

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
NSLog(@"locationManagerdidUpdateHeading() was called.");
if (newHeading.headingAccuracy < 0) {
    NSLog(@"the heading accuracy is smaller than 0.  returning.");
    return;
}

// Use the true heading if it is valid.
CLLocationDirection theHeading = ((newHeading.trueHeading > 0) ?
                                  newHeading.trueHeading : newHeading.magneticHeading);
NSString* myNewString = [NSString stringWithFormat:@"the heading is %d", theHeading];
NSLog(myNewString);

}

My code is entering the startHeadingEvents method (based on my logging) but is crashing before exiting the method (based on my logging not being called). I assume copyWithZone (which is in the error) is a method of the CLLocationManager being called internally at some point. I’m sure I’m making an amateur mistake somewhere, can someone point me in the right direction?

  • 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-29T05:29:28+00:00Added an answer on May 29, 2026 at 5:29 am

    Your problem is that you are using “copy” in your property for the CLLocationManager, which is a singleton – often Singletons are defined such that they throw an exception to prevent copying the single instance.

    Instead, declare your property like so:

    @property(nonatomic, strong) CLLocationManager *locManager;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So let me qualify this by saying that I'm very new to NASM. I'm
Let's say I dynamically create a timer like this: System.Timers.Timer expirationTimer = new Timer(expiration
Hi i m looking forward to creat a form that let people upload new
Let me qualify this question. I'm working on a classic ASP.NET application (Web Forms)
Let's say I'm starting a new project, quality is a top priority. I plan
Let's aggregate a list of free quality web site design templates. There are a
Let's say I have this MySQL table: OK.. see the type field? Type 0
Let's say R is a mxn random matrix. How can generate R with each
Let's say i have this block of code, <div id=id1> This is some text
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):

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.