1

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.

Mike
  • 481
  • 10
  • 24
  • Did you set the Delegate? Do you have any Bluetooth Low-Energy (and not classical bluetooth, the question of CBUUID made me wonder) devices to find? – Larme Feb 06 '14 at 15:20
  • yes, I set the delegate so: m_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; About BLE, I use iPad Air and MacBook Air in pair. no third-party device yet. – Mike Feb 06 '14 at 15:33
  • just I'm trying to make some connection between two devices while I don't have an original device. but it found nothing – Mike Feb 06 '14 at 15:38
  • Do you get any result if you _don't_ pass a list of services into `scanForPeripheralsWithServices:`? - i.e. if you pass nil? – James Frost Feb 06 '14 at 15:42
  • I've nothing. and the state of central manager is CBCentralManagerStatePoweredOn – Mike Feb 06 '14 at 15:47
  • Is one of them a Peripheral and the other one Central? If not, I suggest you use an app like LightBlue that can simulate a peripheral (your next third party device). – Larme Feb 06 '14 at 15:55

2 Answers2

1

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

mwalling
  • 1,745
  • 1
  • 19
  • 26
l0gg3r
  • 8,864
  • 3
  • 26
  • 46
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.

TKAB
  • 174
  • 1
  • 7
  • Thanks, I understood because of your explanation – Mike Feb 28 '14 at 14:00
  • what about a bluetooth keyboard or another iphone instead of a heart rate belt? Because frankly i am not able to discover any peripheral. I am even scanning for all services and still nothing found. [central scanForPeripheralsWithServices:service options:options]; – iosMentalist Jul 31 '14 at 12:02