19
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOS8 CoreLocation

Posted at

iOS8から位置情報を取得する方法が変わりました。
・位置情報を取得する旨を、プログラム側でRequestする必要があります。
・info.plistに、2つのKEYを設定する必要があります。

###位置情報を取得する旨を、プログラム側でRequestする

ViewController.m
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface ViewController () <CLLocationManagerDelegate>

@end

@implementation ViewController
{
    CLLocationManager *_manager;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    _manager = [CLLocationManager new];
    [_manager setDelegate:self];
    

    // iOS8未満は、このメソッドは無いので
    if ([_manager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        
        // GPSを取得する旨の認証をリクエストする
        // 「このアプリ使っていない時も取得するけどいいでしょ?」
        [_manager requestAlwaysAuthorization];
    }
    
    [_manager startUpdatingLocation];
}

###info.plistに、2つのKEYを設定する必要
スクリーンショット 2014-09-19 1.51.42.png

<key>NSLocationWhenInUseUsageDescription</key>
<string>The spirit of stack overflow is coders helping coders</string>

<key>NSLocationAlwaysUsageDescription</key>
<string>I have learned more on stack overflow than anything else</string>

あとは同じかな?

19
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?