iBeacon Stick-N-FindをiPhoneアプリで動かしてみる その2
動いたので中身を見てみます。
BeaconTableViewController.mのこちらでiBeacon一覧を作成してます。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BeaconTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: @"BEACONCELL" forIndexPath:indexPath];
LeSnfDevice *device = [[self getBeaconArray]objectAtIndexedSubscript:indexPath.row];
cell.nameLbl.text = device.name == nil ? [NSString stringWithFormat:@"Beacon %d", indexPath.row] : device.name;
cell.rssiLbl.text = [NSString stringWithFormat:@"%d", device.rssi];
return cell;
}
で実際のconnect,disconnectの部分は、ViewController.m
- (IBAction)connectOrDisconnect:(id)sender {
switch (theDevice.state) {
case LE_DEVICE_STATE_CONNECTED:
case LE_DEVICE_STATE_CONNECTING:
[theDevice disconnect];
[cntBtn setTitle:@"Connect" forState:UIControlStateNormal];
break;
case LE_DEVICE_STATE_DISCONNECTED:
[theDevice connect];
[cntBtn setTitle:@"Disconnect" forState:UIControlStateNormal];
break;
default:
//LE_DEVICE_STATE_UPDATING_FIRMWARE so just let it be
break;
}
音を鳴らす部分もこれだけです。
SDKがあると簡単ですね。
- (IBAction)pageBeacon:(id)sender {
[theDevice enableAlertSound:YES light:YES]; //if connect page ... else nothing will happen
}
ただbluetoothのペアリングをする必要があるんだけど、これってマストなのかな?
通常店舗とかで使う場合なんか面倒ですね。