Solution to Bronze and Silver Challenges


Hi All,

So, I actually implemented some extra code for the silver challenge to check if the H/W the app was on, supports compass data

Here are the files


#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface WhereamiViewController : UIViewController <CLLocationManagerDelegate> //Conforms to the CLLOcationManager protocol 

    CLLocationManager *locationManager; 



#import "WhereamiViewController.h"

@interface WhereamiViewController ()


@implementation WhereamiViewController

- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
        //Create a location manager object

    locationManager = [[CLLocationManager alloc]init];

        //There will be a warning message from this line of code - ignore it for now.

    [locationManager setDelegate:self];
        //We want it to be as accurate as possible - regardles of power/time useage

    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

        //__Bronze Challenge____________
    [locationManager setDistanceFilter:50];

        ///__Silver Challenge______________

        //Check to see if H/W supports heading data
    if ([CLLocationManager headingAvailable] == YES)
        [locationManager startUpdatingHeading];
            NSLog (@ "No Compass found!!" );

        //Tell the manager to start looking for its location now
    [locationManager startUpdatingLocation];

    return self;
    //Update delegate with new location

- (void) locationManager: (CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation: (CLLocation *)oldLocation
    NSLog (@ "%@", newLocation); 

    //__Silver challenge_____

    // Update delegate with new heading

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


    //Update delegare should there be an error

- (void) locationManager: (CLLocationManager *)manager
didFailWithError: (NSError *)error
    NSLog ( @ "Failed to update location: %@", error); 

- (void) dealloc
        //Tell the locationmanager to stop sending us messages

    [locationManager setDelegate:nil];

After reading the Apple documentation - I found that the method used for checking if H/W has support for compass was deprecated in iOS 6.0 - so, I found the replacement, which is a class method.

Tested this on the device and works 100%


So I have the exact same code, except trying on my iOS7 phone. It’s not printing the NSLog heading…