Reputation: 763
I need to update the location only one time,but when i try to stop to update it wont work...
the .h file :
@protocol CoreLocationControllerDelegate
@required
- (void)locationUpdate:(CLLocation *)location; // Our location updates are sent here
- (void)locationError:(NSError *)error; // Any errors are sent here
@end
@interface CoreLocationController : NSObject <CLLocationManagerDelegate>
{
CLLocationManager * locMgr;
id delegate;
}
@property (nonatomic, retain) CLLocationManager *locMgr;
@property (nonatomic, assign) id delegate;
@end
the .m file:
@synthesize locMgr,delegate;
- (id)init {
self = [super init];
if(self != nil) {
self.locMgr = [[[CLLocationManager alloc] init] autorelease]; // Create new instance of locMgr
self.locMgr.delegate = self; // Set the delegate as self.
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)])
{ // Check if the class assigning itself as the delegate conforms to our protocol. If not, the message will go nowhere. Not good.
[self.delegate locationUpdate:newLocation];
[self.locMgr stopUpdatingHeading];
[self.locMgr setDelegate:nil];
}
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) { // Check if the class assigning itself as the delegate conforms to our protocol. If not, the message will go nowhere. Not good.
[self.delegate locationError:error];
}
}
I tried in the class and when i declare it on my viewcontroller,but both wont seem to work....
Upvotes: 0
Views: 708
Reputation: 14164
Have you tried using -stopUpdatingLocation rather than heading?
Upvotes: 1