Challenge Help, Please


#1

Hi,

Just a little help please with the Challenge. I’m unable to get the heading information to print out to the log.

Here’s what I have done:

  1. I’ve checked to see if the heading is available. I get true.
  2. I set the heading filter and the heading orientation
  3. I start the generation of heading updates
  4. I implemented the method locationManager:didUpdateHeading:

My problem is that locationManager:didUpdateHeading is never called. The NSLog statement inside this method is never displayed. Can anyone shed some light onto what I might be doing wrong?

Thanks,
Kitwana


#2

Is the location manager that is handling headings have its delegate pointer set to the object you have implemented locationManager:didUpdateHeading: in?

Are you sure you have no typos in the method declaration? (Copied from Docs?)

Are you running on a device?


#3

Assuming that the program is running perfectly before implementing any challenge-related code, all I did was add two things based on the hint provided in the text.

Step 1: Send a message to locationManager with respect to heading information

// Tell our manager to start looking for its heading immediately [locationManager startUpdatingHeading];

Step 2: Implement appropriate delegate method

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { NSLog(@"Heading Information: %@", newHeading); }


#4

I made effectively the exact same changes and have the exact same results (i.e. none.) Does this have to do with certain things being deprecated in iOS 4 - including locationAvailable as a property (recommending to use the class method instead)?

Update: It appears that the problem is in the simulator - which interestingly reports location services as being available, but does not actually return any heading information… nor does it provide anything in the UI to emulate a compass event. Deploying the code on my phone works fine.


#5

Same case here. Can we have confirmation from the authors that the challenge does not work in simulator but only on devices? Or anyone manage to get it work on the simulator?


#6

Heading information is only available on the device and only the 3GS and iPhone 4.


#7

I too thought the solution was along the lines of what Pharmx did, sending the startUpdatingHeading message to locationManager, and implementing the locationManager:didUpdateHeading: delegate method. I was disappointed when I couldn’t confirm this in the simulator. This “challenge” thus seems to be a bit unfair, especially considering it was the first real challenge posed in the book.

So since the challenge isn’t fair, here’s a somewhat unfair way to satisfy at least part of the challenge with the simulator: just add the line

NSLog(@"Heading: %@", [locationManager heading]);
inside the locationManager:didUpdateToLocation:fromLocation: delegate method. Like this…

[code]- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@“Location: %@”, newLocation);

NSLog(@"Heading: %@", [locationManager heading]);

}[/code]

This at least seems to print out a (null) for heading when using the simulator targeting iOS4. Since I don’t have an iPhone4, I can’t confirm that this prints out a real heading when one exists. Perhaps someone who has one would kindly test this.


#8

Hi,

Just tried this and can confirm that this does output real heading info on a 3GS device running iOS4.

It also outputs a null or two at the beginning as the didUpdateToLocation event can trigger before the heading info is available.

if you put the log statement in the didUpdateHeading event then you dont get the initial nulls.

HTH
Gareth


#9

It doesn’t work on my iPod Touch (iOS 4.2) either. So I was really scratching my head until I read this thread. If only I’d checked out the forum earlier!


#10

I was working on this challenge and found this post. This little extra code certainly helps and helped me to determine that a mac mini does not support header info:

NSLog(@"%@", [CLLocationManager headingAvailable]?@"YES":@"NO"); if([CLLocationManager headingAvailable]){ [locationManager startUpdatingHeading]; }