I can't get heading information

2019-08-10 20:34发布

问题:

I'm trying to get heading information using ios 4.3 on an iphone 4. I have my delegate set correctly but the following delegate method is not being called. Any ideas on what I'm doing wrong?

  • (void)locationManager:(CLLocationManager *)manager didUpdateHeading: (CLHeading )newHeading)newHeading {

    [manager setDelegate:self];

    NSLog(@" I'm updating the location information now");

    [manager startUpdatingHeading];

    NSLog(@" heading info %@",newHeading); }

回答1:

It looks like you're only telling the Location Manager that you want it to issue updates from within the function it calls when it issues updates, so there's a bit of a chicken-and-egg problem here. Move the calls to -setDelegate: and -startUpdatingHeading to someplace where they're sure to get called, like -viewWillAppear or init. Make sure that the code is actually being executed.