no errors — compile time or exceptions thrown at run time… builds fine. Am I doing the memory management wrong? ARC is enabled for all files.
viewcontroller.h:
#import <UIKit/UIKit.h>
@interface workViewController : UIViewController
<CLLocationManagerDelegate>{
CLLocationManager *locationManager;
}
@property (strong, nonatomic) IBOutlet CLLocationManager *locationManager;
@end
viewcontroller.m :
#import "workViewController.h"
@interface workViewController ()
@end
@implementation workViewController
@synthesize locationManager;
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"i worked lol");
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the
//view, typically from a nib.
locationManager.delegate = self;
[locationManager startUpdatingLocation];
}
- (void)viewDidUnload
{
[locationManager stopUpdatingLocation];
[self setLocationManager:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
prefix.pch:
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#endif
Anyway, this code worked once the first time I built the app. Ive been struggling a lot with this, mainly it working sometimes and other times not working at all until i restart my computer. Am I doing memory management completely wrong?
this perplexes me because I made sure I followed tutorials line by line….
the application breaks at where the delegate method is invoked:
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
It just says thread1 breakpoint… and I’m not sure how to read the debugger (It just provides some hex that I don’t know what to do with…)
Anyway, I would love to know what I’m doing wrong!
Try to init your CLLocationManager object. In general, the way you chose to do this is pretty strange. Typically with Core Location, you would create an object that implements didUpdateToLocation as well as didFailWithError, create a delegate protocol, and init this object in your main thread where you need the location, and then call startUpdatingLocation.