nainsi gupta
nainsi gupta

Reputation: 163

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);
}

Upvotes: 6

Views: 2090

Answers (3)

Arda Keskiner
Arda Keskiner

Reputation: 792

Are you asking for authorization for using location? You need to use

[locationManager requestWhenInUseAuthorization];

or

[locationManager requestAlwaysAuthorization];

Upvotes: 0

Simon
Simon

Reputation: 1076

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;
}

Upvotes: 2

tuledev
tuledev

Reputation: 10317

Maybe you forgot delegate in .h flie <CLLocationManagerDelegate>

Upvotes: 0

Related Questions