Late to the game: WhereAmI app stuck after tapping "Done"


#1

Hi all,

I am using the 3rd edition of the book with the iOS 6.1 SDK and Xcode 4.6

I am at the point where the app does not progress beyond receiving the user input text. I see the log line “Resigning first responder” in my WhereamiViewController.m (pasted below) but not the location from foundLocation. I have tried both didUpdateToLocation and didUpdateLocations.

I’ve also attempted the hack as you can see …

Any suggestions would be greatly appreciated!

(I originally created this post/thread in the iPhone Programming topic … that one can be deleted or moved to replace this one?)

//
//  WhereamiViewController.m
//  Whereami
//
//  Created by pekkle on 7/18/13.
//  Copyright (c) 2013 pekkle, Inc. All rights reserved.
//

#import "WhereamiViewController.h"
#import "BNRMapPoint.h"

@interface WhereamiViewController ()

@end

@implementation WhereamiViewController

- (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];
    }
    return self;
}

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

- (void) viewDidLoad
{
    [worldView setShowsUserLocation:YES];
}

- (void) findLocation
{
    [locationManager startUpdatingLocation];
    [activityIndicator startAnimating];
    [locationTitleField setHidden:YES];
}

- (void)foundLocation:(CLLocation *)loc
{
    NSLog(@"Making map point annotation");
    CLLocationCoordinate2D coord = [loc coordinate];
    BNRMapPoint *mp = [[BNRMapPoint alloc] initWithCoordinate:coord
                                                        title:[locationTitleField text]];

    [worldView addAnnotation:mp];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 250, 250);
    [worldView setRegion:region animated:YES];

    [locationTitleField setText:@""];
    [activityIndicator stopAnimating];
    [locationTitleField setHidden:NO];
    [locationManager stopUpdatingLocation];
    
}


#pragma mark delegate protocols

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    CLLocationCoordinate2D loc = [userLocation coordinate];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
    [worldView setRegion:region animated:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self findLocation];

    [textField resignFirstResponder];

    NSLog(@"Resigning first responder");
    return YES;
}

/*
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"%@", [locations lastObject]);
    NSLog(@"%@", [manager location]);

    NSTimeInterval t = [[[[locations lastObject] location] timestamp] timeIntervalSinceNow];

    if (t < -180) {
        return;
    }

    [self foundLocation:[[locations lastObject] location]];
}
*/

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
                                                            fromLocation:(CLLocation *)oldLocation
{
    if(TARGET_IPHONE_SIMULATOR){
        [newLocation initWithLatitude:37.33168900 longitude:-122.03073100];
    }
    
    NSLog(@"%@", newLocation);

    NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];

    if (t < -180) {
        return;
    }
    [self foundLocation:newLocation];
}



@end

And it gets stuck here:

2013-07-25 00:25:58.987 Whereami[18685:c07] Resigning first responder

#2

The code supplied appears to be OK - could you also paste your BNRMapPoint interface/implementation code?

Nick


#3

Why is that statement commented out?

- (id)initWithNibName:(NSString *) nibNameOrNil: bundle:(NSBundle *)nibBundleOrNil
{
...
    if (self) {
...
        //[locationManager startUpdatingLocation];
    }
...
}

#4

[locationManager startUpdatingLocation] is not required in the initWithNibName: method for this particular project as it is used in the findLocation: method.