Developer Day
iBeacon
まるごと体験ツアー
1
A-1
小室 啓, iPhoneアプリサービス事業部札幌チームリーダー
クラスメソッド株式会社
Ⓒ Classmethod, Inc.
2015年03月29日
J-1
Twitter: #cmdevio2015J
Profile
KOMURO, Hiraku (小室 啓)
埼玉 → 東京 → 札幌
2014 年 10 月から札幌
iPhoneアプリサービス事業部札幌チームリーダー
PL,Android, parse.com, Ingress(Resistance)
Copyright © Classmethod, Inc.
チョットデキル
Copyright © Classmethod, Inc.
Sapporo
Copyright © Classmethod, Inc.
Supporter Profile
OHMURA,Takatoshi
東京(秋葉原)
iOS,Android, PHP, RDB, Embedded
Ingress(Enlightened)
Copyright © Classmethod, Inc.
Supporter Profile
ARAKAWA,Yasuhisa
東京(秋葉原)
iOS, Cocos-2dx, Develop Game
Copyright © Classmethod, Inc.
アジェンダ
iBeacon の説明
iBeaconを体験
iBeaconをプログラミング
Discussion
Copyright © Classmethod, Inc.
Some Question
Do you have Android or iPhone?
Are you iOS Application Developer?
What is your favorite Programming Language?
Do you know iBeacon?
Copyright © Classmethod, Inc.
Beacon
原義は狼煙や 火といった位置と情報を伴った伝達手段の
こと
21世紀初頭に於いては主に「無線標識」を指す
無線標識 = 電波灯台
Copyright © Classmethod, Inc.
Beacon 端末
光や電波などを発する固定された装置のこと
その光を見た人や信号を受信した電子機器などが現在地を
知るのに使われる
Copyright © Classmethod, Inc.
iBeacon とは
Apple 社の登録商標
屋内測位システム
BLE (Bluetooth Low Energy) を使用
iOS 7 以降で利用可能
Copyright © Classmethod, Inc.
iBeacon 使用例
Copyright © Classmethod, Inc.
https://www.youtube.com/watch?v=SrsHBjzt2E8
できること
Beacon 端末までの近接度を 3 段階で測定できる
Immediate, Near, Far
Beacon 端末観測領域への入場/退場を検知できる
Copyright © Classmethod, Inc.
できないこと
Beacon 端末の位置を知ること
Beacon 端末までの距離を測ること
位置以外の情報取得
Copyright © Classmethod, Inc.
Beacon 端末の識別子
proximity UUID
128 bit(例:00000000-B9C9-1001-B000-001C4D04DDAB)
major
16 bit(例:4)
minor
16 bit(例:12)
Copyright © Classmethod, Inc.
電波干渉
Copyright © Classmethod, Inc.
手に入れろ!
Copyright © Classmethod, Inc.
7 つの Beacon 端末
制限時間は 15 分
全て見つけた人はどんな願いでも叶う!(かもしれない)
※貴重品は一応所持していってください
Copyright © Classmethod, Inc.
願いは叶いましたか?
Copyright © Classmethod, Inc.
アプリの仕組み
Copyright © Classmethod, Inc.
Beacon の設定
Copyright © Classmethod, Inc.
- (void)setupBeacons
{
if ([[CLLocationManager class] respondsToSelector:@selector(isMonitoringAvailableForClass:)] &&
[CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) {
self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
for (NSDictionary *beaconInfo in [[BeaconManager sharedManager] beaconsInformation]) {
CLBeaconRegion *beaconRegion =
[[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:beaconInfo[@"uuid"]]
major:[beaconInfo[@"major"] integerValue]
minor:[beaconInfo[@"minor"] integerValue]
identifier:beaconInfo[@"identifier"]];
[self.locationManager startRangingBeaconsInRegion:beaconRegion];
}
}
}
デリゲートメソッド
Copyright © Classmethod, Inc.
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region
{
CLBeacon *beacon = beacons.firstObject;
Ball *dragonBall = [self ballWithIdentifier:region.identifier];
switch (beacon.proximity) {
case CLProximityImmediate:
[manager stopRangingBeaconsInRegion:region];
[dragonBall found];
self.numberOfFound++;
if (self.numberOfFound >= kNumberOfBalls) [self foundAll];
break;
case CLProximityNear:
[dragonBall startAnimationWithProximity:CLProximityNear];
break;
case CLProximityFar:
[dragonBall startAnimationWithProximity:CLProximityFar];
break;
case CLProximityUnknown:
[dragonBall stopAnimation];
break;
}
}
http://goo.gl/gWIAhM
Copyright © Classmethod, Inc.
10 分休憩
Copyright © Classmethod, Inc.
作ってみる
現在いくつの Beacon 端末の観測領域に入っているかを検出
するアプリ
使用する Beacon 端末は 3 つ
入っている観測領域の数によって背景色を変える
Copyright © Classmethod, Inc.
イメージ図
3 つの円の中心それぞれに Beacon 端末があるイメージ
Copyright © Classmethod, Inc.
0 1 2 3
b
b b
注意点
iPhone の Bluetooth は ON にする
アプリ起動時、ユーザーに位置情報の使用許可をもらう
iOS 8 では以下の処理が必要
CLLocationManager#requestAlwaysAuthorization
Info.plist に NSLocationAlwaysUsageDescription を追加する
Copyright © Classmethod, Inc.
Welcome! Any your Question
Supporterの方々はiOSアプリケーション開発のプロです。分
からない事があれば、どんどん質問してください。
Copyright © Classmethod, Inc.
Let’s Start !!
Copyright © Classmethod, Inc.
Beacon 情報
proximity UUID
00000000-B9C9-1001-B000-001C4D04DDAB
major / minor
1 / 1
1 / 3
1 / 4
Copyright © Classmethod, Inc.
Sample Answer
Copyright © Classmethod, Inc.
http://goo.gl/vNg4aB
Copyright © Classmethod, Inc.
プログラム例
Copyright © Classmethod, Inc.
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region
{
CLBeacon *beacon = beacons.firstObject;
switch (beacon.proximity) {
case CLProximityImmediate:
[self setIsNearBeaconWithValue:NO major:beacon.major minor:beacon.minor];
break;
case CLProximityNear:
[self setIsNearBeaconWithValue:YES major:beacon.major minor:beacon.minor];
break;
case CLProximityFar:
[self setIsNearBeaconWithValue:NO major:beacon.major minor:beacon.minor];
break;
case CLProximityUnknown:
[self setIsNearBeaconWithValue:NO major:beacon.major minor:beacon.minor];
break;
}
[self changeBackgroundColor];
}
プログラム例
Copyright © Classmethod, Inc.
- (void)setIsNearBeaconWithValue:(BOOL)value
major:(NSNumber *)major
minor:(NSNumber *)minor
{
if (([major intValue] == kBeaconMajorValue1) &&
([minor intValue] == kBeaconMinorValue1)) {
self.isNearBeacon1 = value;
} else if (([major intValue] == kBeaconMajorValue2) &&
([minor intValue] == kBeaconMinorValue2)) {
self.isNearBeacon2 = value;
} else if (([major intValue] == kBeaconMajorValue3) &&
([minor intValue] == kBeaconMinorValue3)) {
self.isNearBeacon3 = value;
}
}
プログラム例
Copyright © Classmethod, Inc.
- (void)changeBackgroundColor
{
NSUInteger nearCount = self.isNearBeacon1 + self.isNearBeacon2 + self.isNearBeacon3;
switch (nearCount) {
case 1: self.view.backgroundColor = [UIColor cyanColor]; break;
case 2: self.view.backgroundColor = [UIColor yellowColor]; break;
case 3: self.view.backgroundColor = [UIColor magentaColor]; break;
default: self.view.backgroundColor = [UIColor whiteColor]; break;
}
}
DiscussionTime
Copyright © Classmethod, Inc.
iBeacon でどんなことができる?
Copyright © Classmethod, Inc.
例えばこんなもの
日本で唯一iBeaconに準拠したビーコンを開発・販売してい
るAplix社
東京メトロの中に数mおきにビーコンを配置。どこで点検
が行われているか、どこまで点検が行われているかを把握
している
Copyright © Classmethod, Inc.
まとめ
Copyright © Classmethod, Inc.
最後に
エンジニア募集中!!
私達と一緒に働きませんか?
広大な北の大地がみなさんを待っています!(東京も可)
http://classmethod.jp/recruit/
※お問い合わせの際は「"スライド"を見た」というとスムーズです。
Copyright © Classmethod, Inc.
Androidもね
Developer Day
ご静聴ありがとうございました。
スライドは後日ブログで公開します。
47
A-1
Ⓒ Classmethod, Inc.
#cmdevio2015J

classmethod devio2015 J-1 iBeacon