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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:39:40+00:00 2026-06-16T05:39:40+00:00

I have a CLLocationManager singleton which implements a protocol, so I can tell another

  • 0

I have a CLLocationManager singleton which implements a protocol, so I can tell another model class (ServerConnection) that an updated location of the user has been found.

In my AppDelegate in the method, didFinishLaunching, I write

ServerConnection* serverConnection = [[ServerConnection alloc] init];
[LocationManager sharedLocationSingleton].delegate = serverConnection;
[[LocationManager sharedLocationSingleton] getUsersLocation];

This doesn’t work and the delegate method in my ServerConnection class isn’t called. However, if I try having my AppDelegate class be the listener, as in the following line, it works fine.

// self refers to AppDelegate
[LocationManager sharedLocationSingleton].delegate = self;

Here, my AppDelegate implements the required delegate method and the method is called when the user’s location is updated, as it should.

Why is my above method failing, where I try to set the delegate to be serverConnection?

Tutorials online usually point to using a UIViewController or the AppDelegate as the “listener”, but in my case, I want a separate model class to be the listener. How do I do that?

Below is my LocationManager singleton class with the protocol

@class LocationManager;

@protocol LocationManagerDelegate <NSObject>
@required
-(void)LocationManagerUpdated:(LocationManager*) locationManager
                  withValue:(CLLocation*) location;
@end

@interface LocationManager : NSObject <CLLocationManagerDelegate>

@property (strong, nonatomic) CLLocationManager* locationManager;
@property (strong, nonatomic) CLLocation* location;
@property (weak, nonatomic) id <LocationManagerDelegate> delegate;

+(LocationManager*)sharedLocationSingleton;
-(void) getUsersLocation;

@end

My header file for Server connection is.

#import <Foundation/Foundation.h>
#import "LocationManager.h"

@interface ServerConnection : NSObject <LocationManagerDelegate>
@end

This works when AppDelegate is set to be the listener, but not my model object ServerConnection. How do I fix this?

Thanks!

  • 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-06-16T05:39:42+00:00Added an answer on June 16, 2026 at 5:39 am

    There should be no problem in doing what you are trying to do (i.e., having a non-controller class instance to act as a delegate).

    This works when AppDelegate is set to be the listener, but not my model object ServerConnection.

    Does your ServerConnection class implement the LocationManagerDelegate protocol? (I mean implement as opposed to just declare it in its interface).

    Check the LocationManager method in charge for calling the delegate method (LocationManagerUpdated:) and add there a NSLog trace to check that the delegate object is correctly set when you try and send it the message.

    EDIT:

    ServerConnection* serverConnection = [[ServerConnection alloc] init];
    [LocationManager sharedLocationSingleton].delegate = serverConnection;
    [[LocationManager sharedLocationSingleton] getUsersLocation];
    

    after you comment, it is clear that the issue stems from instantiating serverConnection in a stack variable and not in a property.

    Your approach of making the delegate property a strong property is not correct since it leads to retain cycles. What you need to do is defining a strong serverConnection property in the class that executes the code I pasted above (the app delegate?).

    If you don’t mind my being rash, if you define the delegate as a strong property, what you are doing is fixing a bug by adding a second bug that hides the first one.

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

Sidebar

Related Questions

I'm writing an app that monitors the user's location. I have a CLLocationManager object
I have a Delegate class that handles responses from CLLocationManager and prints them via
I'm developing an iOS 4 application. I have a ViewController that contains another class.
I have a service class that is CLLocationManager's delegate. If I run the app,
I have an app that uses the CLLocationManager to receive location and heading updates.
Is it OK to put the CLLocationManager Delegate methods in a Singleton class which
I have a method (myMethod) in a class (myClass) which utilizes the CLLocationManager to
Can we change this text? I have used property purpose of CLLocationManager class. But
have written this little class, which generates a UUID every time an object of
I have implemented a CLLocationManager to show user location. Once a user clicks a

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.