Bronze & Silver Challenge


#1

WhereamiViewController.h

[code]#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface WhereamiViewController : UIViewController

{
CLLocationManager *locationManager;
}

// ********************************************************************************************
// *
// Bronze Challenge *
// *

@property (nonatomic, readwrite, assign) CLLocationDistance minDistanceFilter;

// *
// ********************************************************************************************

@end
[/code]
WhereamiViewController.m

[code]#import “WhereamiViewController.h”

@implementation WhereamiViewController

@synthesize minDistanceFilter;

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

    if (self)
    {
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager startUpdatingLocation];

      // ************************************************************************
      //                                                                        *
      //                            Bronze Challenge                            *
      //                                                                        *
      
      [self setMinDistanceFilter:50];
      [locationManager setDistanceFilter:[self minDistanceFilter]];
      
      // Or you can use the following statement and ignore two previous ones,
      // ignoring also the @synthesize directive and the @property directive
      // of the minDistanceFilter added in WhereamiViewController.h
      //[locationManager setDistanceFilter:50];
    
      //                                                                        *
      // ************************************************************************
      
      // ************************************************************************
      //                                                                        *
      //                            Silver Challenge                            *
      //                                                                        *
    
      if ([CLLocationManager headingAvailable])
      {
          [locationManager startUpdatingHeading];
      }
      
      //                                                                        *
      // ************************************************************************
    

    }

    return self;
    }

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

  • (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    {
    NSLog(@“Could not find location: %@”, error);
    }

  • (void)dealloc
    {
    [locationManager setDelegate:nil];
    }

// ********************************************************************************************
// *
// Silver Challenge *
// *

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

// *
// ********************************************************************************************

@end[/code]

Can anybody test it in a device please? Thanks.


#2

now for some reason after about half an hour of typing the code i accidently found a way to get it to read but i dont know how i had to manually type the code did anyone else have this issue ? here is my code

[code]//
// WhereamiViewController.m
// Whereami
//
// Created by troy miller on 10/11/12.
// Copyright © 2012 troy miller. All rights reserved.
//

#import “WhereamiViewController.h”

@interface WhereamiViewController ()

@end

@implementation WhereamiViewController

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

if (self) {
    //create the location manager object
    locationManager = [[CLLocationManager alloc]init];
    
    [locationManager setDelegate:self];
    
    //and we want it to be the most accurate as possible
    //regardless of how much time/power it takes
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    
    // tell the manager to start lookin for it location immediately
    [locationManager startUpdatingLocation];


}

return self;

}

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

@end
[/code]

if anyoen could tell me why i had to type it by hand please let me know. also if anyone can tell me how to turn off " []’ when i press the “:” key to help me in manually typing


#3

fcallau, I wrote the same code as you did, but also can’t verify this. As I got this from google it doesn’t work on simulator.


#4

Hi guys,

I have exactly the same code as fcallau and it is working perfectly on a device!


#5

This challenge will only work on a device. You won’t be able to run it on the simulator.


#6

You can run it on a simulator by changing the simulated location. Once you do, it should NSLog the new location once.


#7

You can run it on a simulator by changing the simulated location. Once you do, it should NSLog the new location once.[/quote]

The bronze portion can run simulated, but the silver part requires a device.