uchicago-mobi / 2016-Winter-Forum

Class Forum for MPCS51030.
3 stars 0 forks source link

Location Manager Issue #217

Closed msylvester closed 8 years ago

msylvester commented 8 years ago

I am having problems with Location Manager, I have implemented the code as described in the lecture "Location, Location, Location".

My program requests authorization and enters the appropriate code block (i.e. alwaysauthorized). However, the functions in the extension to the root view controller class which contains the CLLocation Delegate are never called (i.e. those functions func locationManager(etc., etc)).

I have two extension (including this one) for my root view controller class, I don't know if that is a problem.

Help! Singleton, maybe?

susanstevens commented 8 years ago

Having multiple extensions on your view controller should be fine! Whenever delegate methods aren't being called, the first thing to check is that you've set your delegate properly. Somewhere in your code, you should have:

let locationManager = CLLocationManager()
locationManager.delegate = self

Let me know if that helps!

msylvester commented 8 years ago

Yes, I have the variable declaration (i.e.the let statement) under the class definition and I set the delegate in viewDidLoad prior to determining the authorization status. For the cases, AuthorizedAlways and AuthorizedWhenInUse, I set the properties of location manager and call locationManager.startUpdatingLocation().

Still, tho, no dice

tabinks commented 8 years ago

Look at the Info.plist, make sure that you have the added the additional keys for location services.

msylvester commented 8 years ago

@tabinks. In info.plist:

Required Device Capabilities Item[0] String location-services Item[1] String armv7

This matches your slide except that instead of UIRequiredDeviceCapabalities my plist has Required Device Capabilities. Note, if I try to change it to UIRequiredDeviceCapabalites it says it already exists as Required Device Capabilities.

It doesn't work. Any ideas?

tabinks commented 8 years ago

@msylvester Are you setting the NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription in the Info.plist?

msylvester commented 8 years ago

Yes, they are set.