Contenu connexe
Similaire à classmethod devio2015 J-1 iBeacon (20)
classmethod devio2015 J-1 iBeacon
- 2. Profile
KOMURO, Hiraku (小室 啓)
埼玉 → 東京 → 札幌
2014 年 10 月から札幌
iPhoneアプリサービス事業部札幌チームリーダー
PL,Android, parse.com, Ingress(Resistance)
Copyright © Classmethod, Inc.
- 13. 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.
- 24. 7 つの Beacon 端末
制限時間は 15 分
全て見つけた人はどんな願いでも叶う!(かもしれない)
※貴重品は一応所持していってください
Copyright © Classmethod, Inc.
- 27. 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];
}
}
}
- 28. デリゲートメソッド
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;
}
}
- 33. 注意点
iPhone の Bluetooth は ON にする
アプリ起動時、ユーザーに位置情報の使用許可をもらう
iOS 8 では以下の処理が必要
CLLocationManager#requestAlwaysAuthorization
Info.plist に NSLocationAlwaysUsageDescription を追加する
Copyright © Classmethod, Inc.
- 34. Welcome! Any your Question
Supporterの方々はiOSアプリケーション開発のプロです。分
からない事があれば、どんどん質問してください。
Copyright © Classmethod, Inc.
- 39. プログラム例
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];
}
- 40. プログラム例
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;
}
}
- 41. プログラム例
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;
}
}