Это первый раз, когда я разрабатываю приложение. Поэтому я хочу, чтобы координата пользователя, а также адрес отображался, когда пользователь нажимает кнопку «Просмотр местоположения» в контроллере представления.locationManager startUpdatingLocation crashing app
Я закодировал все, и когда я нажимаю кнопку в симуляторе, он внезапно закрывается и указывает мне на код [newlocationManager startUpdatingLocation] в методе кнопки IBAction. Он говорит что-то вроде «thread: 1 breakpoint 1.1». Что это значит и как я могу это исправить?
Это мой интерфейс файла:
@interface FirstViewController : UIViewController <CLLocationManagerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *latitudeLabel;
@property (weak, nonatomic) IBOutlet UILabel *longitudeLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
- (IBAction)getCurrentLocation:(id)sender;
@end
и это мой файл реализации:
#import "FirstViewController.h"
@interface FirstViewController()
@end
#pragma - UIViewController // Categorizes a group of methods
@implementation FirstViewController{
//The CCLocationManager is the object that provides the location data and the methods.
CLLocationManager * newlocationManager;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
newlocationManager = [[CLLocationManager alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma - IBAction // Categorizes a group of methods
- (IBAction)getCurrentLocation:(id)sender {
newlocationManager.delegate = self;
newlocationManager.desiredAccuracy = kCLLocationAccuracyBest;
[newlocationManager startUpdatingLocation];
}
#pragma - CLLocationManagerDelegate // Categorizes a group of methods
// Informs the delegate that it was unable to get location data. Displays error pop-up alert.
- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
// The error why location could not be retreived
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
// Last object of the 'locations' array contains the most recent location. newLocation now points to the last object.
CLLocation *newLocation = [locations lastObject];
CLLocation *oldLocation;
// Check the size of the NSArray (locations). If it contains a single object, just set oldLocation to nil.
// If it contains more than 1 object then store that in oldLocation.
if (locations.count>1){
oldLocation = [locations objectAtIndex:(locations.count - 2)];
}
else
oldLocation = nil;
NSLog(@"didUpdateToLocation %@ from %@", newLocation, oldLocation);
if (newLocation != nil){
_longitudeLabel.text = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.longitude];
_latitudeLabel.text = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.latitude];
}
//MKCoordinateRegion userLocation = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 1500.0, 1500.0);
//[regionsMapView setRegion:userLocation animated:YES];
}
@end
Какая ошибка у вас возникла? это может помочь, если вы измените слабый и сильный. – Bejibun
Удалите контрольную точку в отладчике или нажмите кнопку «Продолжить» после ее остановки. – rmaddy