В настоящее время я создаю приложение для iPhone (Xcode 4.3.1, IOS 5), которое может использовать устройства Bluetooth! Основная цель этого приложения - навигация внутри помещений (GPS внутри зданий не очень точен).
Единственное решение, которое я здесь вижу (чтобы сохранить свое приложение в AppStore), — это попытаться найти доступные устройства Bluetooth!
Я пытался использовать фреймворк CoreBluetooth, но не получил список доступных устройств! Может быть, я не правильно использую эти функции
#import <UIKit/UIKit.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface AboutBhyperView : UIViewController <CBPeripheralDelegate, CBCentralManagerDelegate>
{
CBCentralManager *mgr;
}
@property (readwrite, nonatomic) CBCentralManager *mgr;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
mgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog([NSString stringWithFormat:@"%@",[advertisementData description]]);
}
-(void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals{
NSLog(@"This is it!");
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
NSString *messtoshow;
switch (central.state) {
case CBCentralManagerStateUnknown:
{
messtoshow=[NSString stringWithFormat:@"State unknown, update imminent."];
break;
}
case CBCentralManagerStateResetting:
{
messtoshow=[NSString stringWithFormat:@"The connection with the system service was momentarily lost, update imminent."];
break;
}
case CBCentralManagerStateUnsupported:
{
messtoshow=[NSString stringWithFormat:@"The platform doesn't support Bluetooth Low Energy"];
break;
}
case CBCentralManagerStateUnauthorized:
{
messtoshow=[NSString stringWithFormat:@"The app is not authorized to use Bluetooth Low Energy"];
break;
}
case CBCentralManagerStatePoweredOff:
{
messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered off."];
break;
}
case CBCentralManagerStatePoweredOn:
{
messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered on and available to use."];
[mgr scanForPeripheralsWithServices:nil options:nil];
//[mgr retrieveConnectedPeripherals];
//--- it works, I Do get in this area!
break;
}
}
NSLog(messtoshow);
}
Я не уверен в этой строке, как передать правильные параметры?
[mgr scanForPeripheralsWithServices:nil options:nil];
Я заглянул в ссылку на яблоко .. и до сих пор не понимаю, что это за CBUUID ??? У каждого устройства есть идентификатор bluetooth? Где я могу найти его?
- (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary *)options;
Параметры serviceUUIDs — массив CBUUID, которые интересуют приложение. options — словарь для настройки сканирования, см. CBCentralManagerScanOptionAllowDuplicatesKey.
Есть ли другой способ использовать Bluetooth на IOS? Я имею в виду старые фреймворки, которые не используют BLE 4.0!
Буду признателен за любой совет!
спасибо!