I’m trying to tell a CLLocationManager object that is a property of a viewcontroller to stop updating location when the appDelegate recieves the message that the app will enter background and my problem is that I’m not sure how to refer to the viewController object inside my appDelegate class.
I’m trying to tell a CLLocationManager object that is a property of a viewcontroller
Share
It sounds like you’re taking the wrong approach. Since the location manager is an instance variable on the view controller, it should be the view controller instructing it to stop – not the app delegate.
This is how Cocoa/UIKit/Objective-C are designed to work and anything else is an uphill fight.
Perhaps something like this in your viewController:
But to answer your specific question, from inside your view controller you can use this to access the app delegate:
That will let you to tell it about the view controller. But be careful as you may create a memory leak doing this!
You need to make sure the delegate doesn’t retain your view controller, or else it will never be deallocated. And you need to make sure the delegate’s reference to the view controller is set to nil when the view controller is deallocated.
In general you should avoid having the app delegate know anything at all about any specific view controllers.