I am working on a sport project at the moment.
What i want to do is, when users select the AutoPause switch on, the CLLocationManager
will pause updating location when speed is below a certain level.
Basically, i have figure out how to implement the locationManager
by changes its attribute, but my question is, how can I set CLLocationManager
's attribute from the settingViewController
, whereas the CLLocationManager
instance is in another ViewController
. Thanks in advance.

- 3,244
- 3
- 18
- 29

- 496
- 3
- 21
-
Put the `CLLocationManager` in a singleton ? – Larme Nov 28 '16 at 09:19
-
@Larme I have put it in a singleton but I just can't figure out the approach for changing its attribute from another View Controller – Nan Nov 28 '16 at 09:20
-
Add a method `-(void)updateLocaltionManagerTargetAttributeSetting:(id)setting`, and do `[[YourSingletonClass sharedManager] updateLocaltionManagerTargetAttributeSetting:something]`? – Larme Nov 28 '16 at 09:57
2 Answers
You can use NSNotificationCenter
to send notification to enable/ disable the CLLocationManager
's autopause attribute in another View Controller.
Other approaches can be:
Use class method, it is explained very well in this SO Answer
Use Delegates

- 1
- 1

- 1,683
- 19
- 30
idk what' your problem with CLLocationManager
, do you mean the way to pass object to another view controller? there are several way to do this.See this question:Passing Data between View Controllers
I'm pretty sure that you can pass the CLLocationManager
object to settingViewController
by setting a property of that CLLocationManager
,because passing the object
means pass the reference the object,you can change the object in settingViewController
life cycle,and it affects the CLLocationManager
object which created by ViewController
.

- 1
- 1

- 246
- 1
- 7
-
My problem is, how can i disable/enable CLLocationManager's autopause attribute from View Controller B, as CLLocationManager's instance was inited in View Controller A. – Nan Nov 28 '16 at 09:26
-
1pass the object to another view controller by setting property would be easy,if you using storyboard for transitions, pass the object by segue.see the article on the link plz. – Chaolong_Liao Nov 28 '16 at 09:42
-
Cheers, i think the approach includes pass object and notification, which one do you think is better. – Nan Nov 30 '16 at 05:26