Both challenges (with comments and advice)



If you have a hard time doing this, here are some pointers:

Bronze challenge: Pretty straight-forward, all you need to do is set a property of the locationManager to a value. Read this: … nager.html

And read about the distance filter property.

Silver Challenge: A little harder, as expected :slight_smile: You will need to implement a new method from the locationManagerDelegate protocol, which get’s called every time the device changes heading (given you told it to start looking for the heading), and in order to do that, you must send another message to the locationManager. At the link above, read about the startUpdatingHeading method.

Then search for the CLLocationManagerDelegate in the documentation (link above) and look for the method named locationManager:didUpdateHeading:

After having done these things, you might get a better view on it all. Here is what i did, and it seems to work:

[code]-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {
    // Create location manager object
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate: self];
    // Want it to be as accurate as possible, regardless of power consumption
    [locationManager setDesiredAccuracy: kCLLocationAccuracyBest];
    // Bronze Challenge - update every 50 meters
    [locationManager setDistanceFilter: 50];
    // Silver challenge - update heading filter
    [locationManager setHeadingFilter: 50];
    // Silver challenge - start looking for a heading
    [locationManager startUpdatingHeading];
    // Tell our manager to look for it's location immediately.
    [locationManager startUpdatingLocation];

return self;


// silver challenge - heading information

// Method is called every time the locationManager get’s an update on heading property, and will get called every time the heading is changed by x degrees, where x is the headingFilter property of the locationManager object.

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

    // Simply log to console
    NSLog(@"%@", newHeading);

Hope this helped :slight_smile: hope i did the right thing as well :stuck_out_tongue: let me know how i did!

regards, JBJ


Thanks a lot! This helped me out alot.

My first attempt without this code failed because I didn’t realize that the distanceFilter property had a setDistanceFilter.

Being new to iOS programming I’m certainly thankful for this great book & great forum with amazing people helping me along the way.

I just can’t wait until I can grasp this stuff more fluently


You’r most welcome :slight_smile: glad i helped.

Don’t worry, as long as you know your way around the main aspects of objective-c, all you gotta do is practice and keep at it. You may even have to read certain chapters twice, or maybe even the book twice if you feel it helps you. Do whatever YOU think will help you and make you feel more comfortable learning this. I’m still learning as well, and what i’ve found helped is to read just a little bit EVERY day, maybe just 5 pages, but sometimes more.