BleSearchResultTableViewController.m
4.2キロバイト
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// BleSearchResultTableViewController.m
// jacket_ios
//
// Created by ドラッサル 亜嵐 on 2016/04/27.
// Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
//
#import "BleSearchResultTableViewController.h"
#import "BleSearchResultTableViewCell.h"
@interface BleSearchResultTableViewController ()
@end
@implementation BleSearchResultTableViewController
@synthesize ble;
@synthesize BLEDevicesRssi;
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.BLEDevicesRssi = [NSMutableArray arrayWithArray:ble.peripheralsRssi];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) connectionTimer:(NSTimer *)timer
{
[self.BLEDevices removeAllObjects];
[self.BLEDevicesRssi removeAllObjects];
[self.BLEDevicesName removeAllObjects];
if (ble.peripherals.count > 0)
{
for (int i = 0; i < ble.peripherals.count; i++)
{
CBPeripheral *p = [ble.peripherals objectAtIndex:i];
NSNumber *n = [ble.peripheralsRssi objectAtIndex:i];
NSString *name = [[ble.peripherals objectAtIndex:i] name];
if (p.identifier.UUIDString != NULL)
{
[self.BLEDevices insertObject:p.identifier.UUIDString atIndex:i];
[self.BLEDevicesRssi insertObject:n atIndex:i];
if (name != nil)
{
[self.BLEDevicesName insertObject:name atIndex:i];
}
else
{
[self.BLEDevicesName insertObject:@"RedBear Device" atIndex:i];
}
}
else
{
[self.BLEDevices insertObject:@"NULL" atIndex:i];
[self.BLEDevicesRssi insertObject:@"0" atIndex:i];
[self.BLEDevicesName insertObject:@"RedBear Device" atIndex:i];
}
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"No BLE Device(s) found."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return self.BLEDevices.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *tableIdentifier = @"cell_uuid";
BleSearchResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier forIndexPath:indexPath];
// Configure the cell...
UIFont *newFont = [UIFont fontWithName:@"Arial" size:13.5];
cell.lblUuid.font = newFont;
cell.lblUuid.text = [self.BLEDevices objectAtIndex:indexPath.row];
newFont = [UIFont fontWithName:@"Arial" size:11.0];
cell.lblRssi.font = newFont;
NSMutableString *rssiString = [NSMutableString stringWithFormat:@"RSSI : %@", [self.BLEDevicesRssi objectAtIndex:indexPath.row]];
cell.lblRssi.text = rssiString;
newFont = [UIFont fontWithName:@"Arial" size:13.0];
cell.lblName.font = newFont;
cell.lblName.text = [self.BLEDevicesName objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(ble.isConnected) {
[self.protocol sendDisconnect];
}
[ble connectPeripheral:[ble.peripherals objectAtIndex:indexPath.row]];
}
@end