I have been following this tutorial http://www.devfright.com/ios-6-core-location-tutorial/ to add location services to my ios app. I have imported the Corelocation in my TestFileViewController.h file like so:
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#import <CoreLocation/CoreLocation.h>
@interface TestFileViewController : UIViewController <UITableViewDelegate,UITableViewDataSource, NSStreamDelegate>
@property (nonatomic, strong) CLLocationManager *locationManager;
@end
and then in the testFileViewController.m ViewDidLoad I added (remembering to implement the CLLocationManagerDelegate):
//start checking for location from CoreLocation Framework (currently not working)
if ([CLLocationManager locationServicesEnabled])
{
NSLog(@"location services enabled");
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.delegate = self;
[_locationManager startUpdatingLocation];
};
}
(conditional CLLocationManager executes true and NSLogs) and then right below ViewDidLoad:
//fail to find location, handle error
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
//show found location, return NSLOG for proof
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"Made it to location Manager");
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
NSLog(@"%f",coordinate.latitude);
}
I added the NSLogs just as markers to determine from the console whether or not the functions were being called at all, however neither didFailWithError nor didUpdateToLocation are called.
Yes I know that didUpdateToLocation is deprecated/outdated, and I replaced it with didUpdateLocations and it still did not work so I changed it back.
How can I get my my locationManager to start updating the current location and return coordinate values in the form of strings to be used later in my app? Thanks.