iOS 11.4.1
Xocde 9.4.1
objective-cで位置情報を取得するためのプログラムを作成しました。
こちらのサイトを参考にさせていただきました。
デバッグ時に以下のエラーが出てうまく動作しません。
2018-08-05 17:38:07.995464+0900 Location-C[973:2653283] This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSLocationWhenInUseUsageDescription key with a string value explaining to the user how the app uses this data
info.plistに記載していないエラーということがわかったのですが、記載してもエラーが直りませんでした。原因がよくわからないので、教えてください。
// info.plist
// ViewController.h
#import <UIKit/UIKit.h> @interface ViewController : UIViewController @end
// ViewController.m
#import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewController () <CLLocationManagerDelegate> @property (nonatomic, retain) CLLocationManager *locationManager; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // ユーザから位置情報の利用について承認 if (nil == self.locationManager) { self.locationManager = [[CLLocationManager alloc] init]; // iOS 8以上 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { // NSLocationWhenInUseUsageDescriptionに設定したメッセージでユーザに確認 [ self.locationManager requestWhenInUseAuthorization]; // NSLocationAlwaysUsageDescriptionに設定したメッセージでユーザに確認 //[locationManager requestAlwaysAuthorization]; } } if (nil == self.locationManager) self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // 情報の更新を開始すれば、位置情報を取得 [self.locationManager startUpdatingLocation]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } // GPSで位置情報の更新があったときに呼ばれる - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation* location = [locations lastObject]; // 時間 NSDate* timestamp = location.timestamp; //NSTimeInterval howRecent = [timestamp timeIntervalSinceNow]; //if (abs(howRecent) < 15.0) { NSLog(@"緯度 %+.6f, 経度 %+.6f\n", location.coordinate.latitude, location.coordinate.longitude); // 日時時間 NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy/MM/dd HH:mm:ss"]; //} } @end
回答1件
あなたの回答
tips
プレビュー