1

I have two methods, each which adds a service to the peripheral manager. When I get the didAddService callback I use the [manager startAdvertisingServices:] method with the services that have been added (so the array used as the value for the CBAdvertisementDataServiceUUIDsKey key has either 1 or 2 service UUIDs in it.)

When I add the second service and try to advertise them both, I always get the error Advertising has already started.

I've tried to use [manager stopAdvertising] and then adding the new services, but the stopAdvertising method is asynchronous, so sometimes it still fails (it hasn't stopped advertising by the time I call startAdvertisingServices again.)

I have no problem advertising/reading/writing them individually, and if I wait after calling stopAdvertising I can start advertising them together, but that seems like a hack.

The way I can think of to do this safely is to KVO on the isAdvertising property of the peripheral manager and hold flags for whether or not each service should be advertising, so that I know exactly when the advertising stops and I can safely start again. I'm also not sure if this will have an affect on Centrals in the field if I start and stop advertising just to add new services.

What's the proper way to advertise multiple services using the peripheral manager?

JuJoDi
  • 14,627
  • 23
  • 80
  • 126
  • What's that `startAdvertisingServices:` method? I can't find anything about it – André Fratelli Aug 09 '15 at 21:21
  • Sorry that must have been a method I wrote to advertise multiple services with the PeripheralManager. To solve this problem I kept a state machine tracking which services had been added to the manager, and when they had all been added I started advertising. – JuJoDi Aug 10 '15 at 01:37

0 Answers0