2016-01-11 5 views
-1

Я работаю над простым приложением, чтобы получить текущее местоположение пользователей, используя инфраструктуру Core Location от Apple в Xcode, и когда я запустил приложение, я получаю сообщение об ошибке. Может кто-то, пожалуйста, скажите мне, что я сделал неправильно, благодарю вас заранее. У меня есть этот код здесь в файле реализации.Текущее местоположение пользователя для iOS 8 - приложение не запускается

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController { CLLocationManager *locationManager; 

} 

- (void)viewDidLoad { 
[super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    locationManager = [[CLLocationManager alloc] init]; 

} 



- (void)didReceiveMemoryWarning { 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

- (IBAction)getCurrentLocation:(id)sender { 

locationManager.delegate = self; 
locationManager.desiredAccuracy = kCLLocationAccuracyBest; 

[locationManager startUpdatingLocation]; 



} 

#pragma mark - CLLocationManagerDelegate 



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

if (currentLocation != nil) { 
    _longitudeLabel.text = [NSString stringWithFormat:@"%.8f",  currentLocation.coordinate.longitude]; 
    _latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]; 
} 
} 





@end 

Это файл заголовка ...

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

@interface ViewController : UIViewController <CLLocationManagerDelegate> 


@property (strong, nonatomic) IBOutlet UILabel *latitudeLabel; 

@property (strong, nonatomic) IBOutlet UILabel *longitudeLabel; 

@property (strong, nonatomic) IBOutlet UILabel *addressLabel; 

- (IBAction)getCurrentLocation:(id)sender; 

@end 

И это выход аварии ...

2016-01-11 11:53:58.346 current location practice[1367:32081] ***  Terminating app due to uncaught exception 'NSUnknownKeyException', 
reason: '[<ViewController 0x7ff240d80cb0> setValue:forUndefinedKey:]: 
this class is not key value coding-compliant for the key getCurrentLocation.' 
*** First throw call stack: 
(
0 CoreFoundation      0x000000010ee29f45 __exceptionPreprocess + 165 
1 libobjc.A.dylib      0x000000010e8a3deb objc_exception_throw + 48 
2 CoreFoundation      0x000000010ee29b89 -[NSException raise] + 9 
3 Foundation       0x000000010e470a6b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 
4 UIKit        0x000000010f36104c -[UIViewController setValue:forKey:] + 88 
5 UIKit        0x000000010f58ea71 -[UIRuntimeOutletConnection connect] + 109 
6 CoreFoundation      0x000000010ed6aa80 -[NSArray makeObjectsPerformSelector:] + 224 
7 UIKit        0x000000010f58d454 -[UINib instantiateWithOwner:options:] + 1864 
8 UIKit        0x000000010f367c16 -[UIViewController _loadViewFromNibNamed:bundle:] + 381 
9 UIKit        0x000000010f368542 -[UIViewController loadView] + 178 
10 UIKit        0x000000010f3688a0 -[UIViewController loadViewIfRequired] + 138 
11 UIKit        0x000000010f369013 -[UIViewController view] + 27 
12 UIKit        0x000000010f24251c -[UIWindow addRootViewControllerViewIfPossible] + 61 
13 UIKit        0x000000010f242c05 -[UIWindow _setHidden:forced:] + 282 
14 UIKit        0x000000010f2544a5 -[UIWindow makeKeyAndVisible] + 42 
15 UIKit        0x000000010f1ce396 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131 
16 UIKit        0x000000010f1d49c3 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1750 
17 UIKit        0x000000010f1d1ba3 -[UIApplication workspaceDidEndTransaction:] + 188 
18 FrontBoardServices     0x000000011219f784 -[FBSSerialQueue _performNext] + 192 
19 FrontBoardServices     0x000000011219faf2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 
20 CoreFoundation      0x000000010ed56011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
21 CoreFoundation      0x000000010ed4bf3c __CFRunLoopDoSources0 + 556 
22 CoreFoundation      0x000000010ed4b3f3 __CFRunLoopRun + 867 
23 CoreFoundation      0x000000010ed4ae08 CFRunLoopRunSpecific + 488 
24 UIKit        0x000000010f1d14f5 -[UIApplication _run] + 402 
25 UIKit        0x000000010f1d630d UIApplicationMain + 171 
26 current location practice   0x000000010e3224bf main + 111 
27 libdyld.dylib      0x0000000111d5892d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type  NSException 
(lldb) 

Может кто-то пожалуйста, скажите мне, что я сделал не так и что я могу сделать, чтобы исправить это? Спасибо.

+0

Скорее всего, вы сконфигурировали что-то не так в построителе интерфейса. Убедитесь, что ваш xib/раскадровка указывает на правильный класс, а затем проверьте все ваши IBOutlets и IBActions –

ответ

0

В соответствии с ниже ошибок:

6 CoreFoundation      0x000000010ed6aa80 -[NSArray makeObjectsPerformSelector:] + 224 
7 UIKit        0x000000010f58d454 -[UINib instantiateWithOwner:options:] + 1864 

Кажется, ваш IBAction не ограничен getCurrentLocation метода, или добавлен неправильно.

+0

. Просмотрите эту ссылку: http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this- класс-это-не-ключ? RQ = 1 –

0

Это прямо в верхней части сообщения об ошибке:

2016-01-11 11:53:58.346 current location practice[1367:32081] ***  Terminating app due to uncaught exception 'NSUnknownKeyException', 
reason: '[<ViewController 0x7ff240d80cb0> setValue:forUndefinedKey:]: 
this class is not key value coding-compliant for the key getCurrentLocation.' 

Это говорит вам, что вы пытаетесь использовать ключ с именем getCurrentLocation на классе ViewController, но класс не тот ключ. Скорее всего, это значит, что что-то не так с вашим раскадровкой. Один из сценариев, которые могут вызвать это, - это подключение кнопки к действию с именем getCurrentLocation, но затем удаление этого метода, а не обновление раскадровки.