Jak uzyskać listę dostępnych urządzeń Bluetooth?

Obecnie tworzę aplikację na iPhone ' a (Xcode 4.3.1, IOS 5), która mogłaby korzystać z urządzeń Bluetooth! Głównym celem tej aplikacji jest nawigacja wewnętrzna (GPS wewnątrz budynków nie jest tak naprawdę dokładny).

Jedynym rozwiązaniem, które widzę tutaj (aby utrzymać moją aplikację w AppStore) jest spróbować skanować dostępne urządzenia bluetooth!

Próbowałem użyć frameworka CoreBluetooth, ale nie dostaję listy dostępnych urządzeń! Może nie używam tych funkcji poprawnie

#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); 
} 
Nie jestem tego pewien. linia, jak przekazać prawidłowe parametry?
[mgr scanForPeripheralsWithServices:nil options:nil];
Zajrzałem do Apple reference .. a ja nadal nie rozumiem co to za CBUUID ??? Każde urządzenie ma jakiś identyfikator bluetooth? gdzie mogę go znaleźć?
- (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary *)options;

Parametry serviceuid - szereg Cbuuid aplikacja jest zainteresowany. opcje-Słownik, aby dostosować skanowanie, patrz CBCentralManagerScanOptionAllowDuplicateskey.

Czy jest jakiś inny sposób na korzystanie z Bluetooth na IOS? Mam na myśli starsze frameworki, które nie używają BLE 4.0! Każda rada będzie mile widziana! Dzięki!
Author: mz87, 2012-04-16

5 answers

Ten przewodnik wygląda obiecująco dla Bluetooth 3.0. Pamiętaj, że struktura CoreBluetooth jest przeznaczona tylko dla Bluetooth Low Energy (4.0). At bluetooth.org ' s Dev-pages można zobaczyć kilka przykładów globalnie zdefiniowanych usług, i jak Guan Yang mentionen, można zobaczyć, że usługa tętna jest 0x180d. UUID jednostki jest zdefiniowany przez producenta.

Oto fragment kodu, który może Ci pomóc po drodze.

// Initialize a private variable with the heart rate service UUID    
CBUUID *heartRate = [CBUUID UUIDWithString:@"180D"];

// Create a dictionary for passing down to the scan with service method
NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];

// Tell the central manager (cm) to scan for the heart rate service
[cm scanForPeripheralsWithServices:[NSArray arrayWithObject:heartRate] options:scanOptions]
 21
Author: chwi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-06-20 22:04:56

W Bluetooth są "usługi". Urządzenie publikuje 1..N usługi, a każda usługa ma 1..M cechy. Każda usługa posiada unikalny identyfikator o nazwie UUID .

Na przykład czujnik tętna Bluetooth, który oferuje usługę "tętno", publikuje usługę z UUID 0X180D.

(więcej usług tutaj )

Więc kiedy wykonujesz wyszukiwanie, musisz podać UUID jako kryteria, informując, która usługa ma być wyszukiwana.

 15
Author: viktorvogh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-17 12:32:30

Powinieneś rzucić okiem na jeden z przykładów. Oto odpowiedni wiersz:

[manager scanForPeripheralsWithServices:[NSArray arrayWithObject:[CBUUID UUIDWithString:@"180D"]] options:nil];

(wiem, że jest to przykład Mac OS X, ale API CoreBluetooth iOS jest bardzo podobne.)

CBUUID identyfikuje usługi, które Cię interesują, a nie Urządzenia. Standardowe usługi mają 16-bitowy UUID, w tym przypadku 0x180d dla Monitora Tętna lub być może 0x180a dla informacji o urządzeniu, podczas gdy usługi zastrzeżone mają 128-bitowy UUID (16 bajtów).

Większość urządzeń implementuje urządzenie serwis informacyjny, więc jeśli szukasz jakiegoś urządzenia, możesz spróbować [CBUUID UUIDWithString:@"180A"].

 10
Author: Guan Yang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-04-17 14:45:57

Spróbuj dać to podczas skanowania urządzeń

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil];

 [self.centralManager scanForPeripheralsWithServices:nil options:options];

Będziesz mógł pobrać listę urządzeń w metodzie didDiscoverPeripheral delegate

 3
Author: Jes,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-28 13:46:26

Zachować spokój i używać https://github.com/l0gg3r/LGBluetooth

All you need to do

[[LGCentralManager sharedInstance] scanForPeripheralsByInterval:4
                                                         completion:^(NSArray *peripherals) {
     }];

 0
Author: l0gg3r,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-25 15:26:40