ユーザーの場所を表示するプログラムを作成するために、このチュートリアルに従っています。Xcode に場所をシミュレートするように指示しましたが、シミュレーターでも、アプリケーションが場所を追跡できるようになっていることを確認しました。ただし、コンソールには何も記録されていません。
ヘッダー ファイル:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface WhereamiViewController : UIViewController <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
@end
そしてメインファイル:
#import "WhereamiViewController.h"
@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 setPausesLocationUpdatesAutomatically:NO];
[locationManager startUpdatingLocation];
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
NSLog(@"%@", [locations lastObject]);
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"Error: %@", error);
}
@end