问题
I need to send ASCII-codes via bluetooth to the third-party device. Hope it's possible to do with spp. I could be wrong in terminology. I don't know enough this programming area.
In centralManagerDidUpdateState
I'm scanning for peripherals:
CBUUID *cbuuidService = [CBUUID UUIDWithString:@"0x1101"];
NSArray *service = @[ cbuuidService ];
NSDictionary *options = @{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES };
[central scanForPeripheralsWithServices:service options:options];
but didDiscoverPeripheral
never called.
I tried to scan without services and it has the same effect.
What am I doing wrong? What cbuuid
do I need and where can I find it? Thank for any help.
回答1:
You need to have one device act as a central (which you do) and one as a peripheral device. So assuming that you use your MB Air as the central, you need to start a CBPeripheralManager on your iPad and have it publish and advertise a service. Then you should be able to discover it on your MB.
I guess the easiest way would be to get a working peripheral (e.g. a heart rate belt), so you can familiarize yourself with the usage of CBCentralManager. Then you could start implementing your own peripheral.
PS: I am not sure it is correct to put 0x
at the beginning of the identifier.
回答2:
Believe CoreBluetooth is very hard to use.
Instead of working with that messy framework use LGBluetooth (It woks over CoreBluetooth).
[[LGCentralManager sharedInstance] scanForPeripheralsByInterval:10 completion:^(NSArray *peripherals) { }];
here is a example of scanning by interval.
Check it out https://github.com/l0gg3r/LGBluetooth
来源:https://stackoverflow.com/questions/21606577/diddiscoverperipheral-not-called