LoginSignup
11
12

More than 5 years have passed since last update.

【iBeacon】AppleのiBeaconサンプルアプリをビルドするときの注意

Posted at

iBeaconサンプルアプリ「AirLocale」

Apple Developer Libraryに、iBeaconのサンプルアプリ「AirLocale」が掲載されています。

AirLocate: Using CoreLocation to monitor, range, and configure your device as an iBeacon

しかし、iOS7を想定して書かれているため、iOS8以降に対しては、ビルドはできるのですがうまく動作しません。
理由はiOS8から、位置情報の取得にユーザのパーミッションが必要になったからです。

修正箇所

1. APLAppDelegate.mのapplication:didFinishLaunchingWithOptions:に次のコードを追加する。

APLAppDelegate.m
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
    [self.locationManager requestAlwaysAuthorization];
}

ちなみにrequestWhenInUseAuthorizationrequestAlwaysAuthorizationがあって、前者はアプリを起動しているときだけ、後者はアプリを起動していなときでも位置情報を取得する許可を、ユーザに要求するメソッドです。

2. AirLocate-Info.plistに次の値を追加する

許可を求める際のユーザへのメッセージを設定します。

  • key: NSLocationAlwaysUsageDescription
  • value(String): <何らかのメッセージ>

ちなみにrequestWhenInUseAuthorizationのときのキーはNSLocationWhenInUseUsageDescriptionです。

ソース

ibeacon - Apple AirLocation demo App ranging not shows beacons - Stack Overflow

11
12
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
11
12