title: Why can't I read the device's deviation from the magnetic North with this code?
body: <p>OK the code is now working, but it still needs work. The values I get are "sticky", they are not stable (the magnetic North seems to move a bit every time I try to return to it), and I need to shake the device a bit in order to refresh/wake-up the values..</p>
  
  <p>Game.h</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  #import "CoreLocation.h"
  
  @interface Game : NSObject
  
  &lt;CLLocationManagerDelegate&gt;
  
  @property BOOL stopButtonPressed;
  
  -(void) play;
  
  @end
  </code></pre>
  
  <p>Game.m </p>
  
  <pre><code>@implementation Game
  
  - (id) init 
  {
      self = [super init];
  
      self.stopButtonPressed = NO;
  
      CLLocationManager *locationManager;
  
      locationManager = [[CLLocationManager alloc] init];
  
      locationManager.delegate = self;
  
      return self;
  }
  
  -(void) play 
  {
  
      [locationManager startUpdatingHeading]; 
  
      while(!self.stopButtonPressed)
      {
           double degrees = locationManager.heading.magneticHeading;
  
           int degreesRounded = (int)degrees;
  
           NSLog(@"Degrees : %i", degreesRounded);
      }
  }
  
  @end
  </code></pre>
  
  <p>MyViewController.m</p>
  
  <pre><code>@interface MyViewController()
  {
      Game *game;
  }
  @end
  
  @implementation MyViewController
  
  -(void) viewDidLoad
  {
      game = [[Game alloc] init];
  }
  
  - (IBAction)playPressed:(UIButton *)sender 
  {
      [game performSelectorInBackground:@selector(play) withObject:nil];
  }
  
  - (IBAction)stopPressed:(UIButton *)sender 
  {
      game.stopButtonPressed = YES;
  }
  
  @end
  </code></pre>
  
  <p>What am I doing wrong?</p>