More Related Content Similar to iOS7でのBluetooth LE活用 @ MOSA Software Meeting 2013 (20) More from akihiro uehara (19) iOS7でのBluetooth LE活用 @ MOSA Software Meeting 201316. フラグ
• 02 01 1A
• AD Type 0x01, flag,
• General Discoverable Mode,
• Simultaneous LE and BR/EDR to
Same Device Capable (Controller)
•
Simultaneous LE and BR/EDR to
Same Device Capable (Host)
17. 製造者固有のデータ
!
•
•
1A FF
•
UUID, major, minor, RSSIはビッグエンディアン
•
RSSIはデフォルト値-59dBm (1m離れたところでのRSSI)
4C 00
02 15
AD Type|会社ID | 不明 |
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 EC 4A 17 A5 C5
UUID
|major|minior|RSSI
23. リージョン監視のフロー
2. 領域監視対象の指定と通知を受け取るタイミング指定
CLBeaconRegion *region =
[[CLBeaconRegion alloc]
initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:kBeaconUUID]
identifier:@ identifier ];
!
CLBeaconRegionクラス
BOOL notifyOnEntry :
領域 in, デフォルト YES
BOOL notifyOnExit :
領域 exit, デフォルト YES
BOOL notifyEntryStateOnDisplay : 画面表示時, デフォルト NO
変更
24. リージョン監視のフロー
3. 監視の開始/停止と通知の取得
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
!
[locationManager startMonitoringForRegion:region];
[locationManager stopMonitoringForRegion:region];
!
CLBeaconRegionクラス
BOOL notifyOnEntry :
領域 in, デフォルト YES
BOOL notifyOnExit :
領域 exit, デフォルト YES
BOOL notifyEntryStateOnDisplay : 画面表示時, デフォルト NO
変更
CLLocationManagerDelegateプロトコル
-(void)locationManager:didEnterRegion:
-(void)locationManager:didExitRegion:
-(void)locationManager:didDetermineState:forRegion:
33. PassbookとiBeacon
• Passbook Package Format Reference
•
https://developer.apple.com/library/ios/documentation/UserExperience/
Reference/PassKit_Bundle/Chapters/Introduction.html
• iOS7から
• 指定項目
• UUID/major/minor
• ロック画面表示名
• いくつでも指定可能
69. // デバイスの発見時処理を行います。
// スキャンで指定したサービスがあるデバイスのみが通知されますが、同じような機能を持った対象外の装置を発見す
るかもしれません。
// アドバタイズメント・パケットに含まれる情報は、advertisementDataから得られます。デバイス名などで判別
します。
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral
*)p advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
// 同一機種が周囲に複数あるとき、自分がもっているものだけに接続するには、UUIDが同じかを判定します。
パケット・データ 受信信号強度
// !!注意!! iOS6では、一度も接続したことがない装置のUUIDはnilになります。一度でも接続すればUUIDが
取れます。ここでは、一度は接続したことがある前提でUUIDを比較しています。
/*
CBUUID *targetUUID = [CBUUID UUIDWithString:@"00000000-0000-0000-2F0C-F0289947EA35"];
if(peripheral.UUID == nil || ! [[CBUUID UUIDWithCFUUID:peripheral.UUID].data
isEqualToData:targetUUID.data]) return;
*/
NSString *localName = [advertisementData
objectForKey:CBAdvertisementDataLocalNameKey];
if(localName != nil && [localName isEqualToString:kTargetDeviceName] ) {
PeripheralContainer *c = [[PeripheralContainer alloc] init];
c.peripheral = p;
c.RSSI = RSSI;
[self findPeripheral:c];
}
}
KeyFobController.m 318行
73. -(void)connect:(PeripheralContainer *)c {
//ターゲットを発見、接続します
//この時点でperipheralはcentral managerに保持されていません。
必ずretain
//少なくとも接続が完了するまでの間、peripheralをアプリ側で保持します。
//接続処理はタイムアウトしません。接続に失敗すれば centralManager:didFailToConnectPeripheral:error
//接続処理を中止するには、peripheralを開放するか、明示的に cancelPeripheralConnection を呼び出します
!
self.peripheral = c.peripheral;
[_centralManager connectPeripheral:self.peripheral options:nil];
}
-(void)disconnect {
// 切断処理をします。_peripheralをnilにするなどの、切断完了後処理は、
// centralManager:didDisconnectPeripheral:error:
// で行います。
[_centralManager cancelPeripheralConnection:self.peripheral];
}
- (void)centralManager:(CBCentralManager *)central
didConnectPeripheral:(CBPeripheral *)p;
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:
(CBPeripheral *)peripheral error:(NSError *)error;
KeyFobController.m 256行
delegateで通知
82. #define kImmediateAlertServiceUUID @"1802"
#define kLinkLossServiceUUID
@"1803"
#define kAlertLevelUUID
@"2A06"
...
_linkLossServiceUUID
= [CBUUID UUIDWithString:kLinkLossServiceUUID];
_immediateAlertServiceUUID = [CBUUID UUIDWithString:kImmediateAlertServiceUUID];
_alertLevelUUID
= [CBUUID UUIDWithString:kAlertLevelUUID];
KeyFobController.m 104行
// 接続
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)p {
// サービスを探します
self.peripheral.delegate = self;
[p discoverServices:[NSArray arrayWithObjects:
_linkLossServiceUUID,
_immediateAlertServiceUUID,
_txPowerServiceUUID,
_batteryLevelServiceUUID,
nil]];
}
KeyFobController.m 343行
83. //発見したサービスに対して、Characteristicsを探します
- (void)peripheral:(CBPeripheral *)p didDiscoverServices:(NSError *)error {
for (CBService *service in p.services) {
if ([service.UUID.data isEqualToData:_linkLossServiceUUID.data]) {
[p discoverCharacteristics:[NSArray arrayWithObjects:
_alertLevelUUID,
nil]
forService:service];
} else if ([service.UUID.data isEqualToData:_immediateAlertServiceUUID.data]) {
[p discoverCharacteristics:[NSArray arrayWithObjects:
_alertLevelUUID,
nil]
forService:service];
KeyFobController.m 367行
- (void)peripheral:(CBPeripheral *)p didDiscoverCharacteristicsForService:(CBService
*)service error:(NSError *)error
{
if ([service.UUID.data isEqualToData:_batteryLevelServiceUUID.data]) {
_batteryLevelCharacteristics = [self findCharacteristics:service.characteristics
uuid:_batteryLevelUUID];
_batteryLevelSwitchCharacteristics = [self
findCharacteristics:service.characteristics uuid:_batteryLevelSwitchUUID];
[p setNotifyValue:YES forCharacteristic:_batteryLevelSwitchCharacteristics];
[p readValueForCharacteristic:_batteryLevelCharacteristics];
[p readValueForCharacteristic:_batteryLevelSwitchCharacteristics];
}
}
KeyFobController.m 396行
94. サービス、動向
• Facebook BTLEグループ
• https://www.facebook.com/groups/
563064710384459/
• Kickstarter ?
• http://www.kickstarter.com/discover/
recently-launched
97. • ReginをON
• 位置の利用を許可
• RangingをON
• どなたか、ビーコン発信?
!
ビーコンの受信
• ビーコン:UUID/Major/Minor
• Proximity:おおよその距離
• RSSI 受信信号(対数 dBm)
• Accuracy:だいたいの精度(m)