Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didUpdateHeading not Called

I want to use compass for update Heading . But my didUpdateHeading not called . I am newer in iOS . Please help any help would be apperciated.

@interface ViewController : UIViewController<CLLocationManagerDelegate>
@property (nonatomic, retain) CLLocationManager     *locationManager;
locationManager=[[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate=self;
    //Start the compass updates.

    [locationManager startUpdatingHeading];

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
    NSLog(@"New true heading: %f", newHeading.trueHeading);
}
like image 731
nainsi gupta Avatar asked Aug 21 '15 07:08

nainsi gupta


1 Answers

The code you provided (assuming you haven't changed anything when pasting here) is missing a function or a code of block to run the first part, I suggest you put it in your viewController init, like so:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {        
         locationManager=[[CLLocationManager alloc] init];
         locationManager.desiredAccuracy = kCLLocationAccuracyBest;
         locationManager.delegate=self;
         //Start the compass updates.

         [locationManager startUpdatingHeading];
    }
    return self;
}
like image 161
Simon Avatar answered Oct 04 '22 20:10

Simon