DCDC DCDC - 9 months ago 50
iOS Question

How to remove/unsubscribe from service in core bluetooth?

I try to achieve it in the following way:

peripheral.services?.removeAll()


but it returns the error


cannot use mutating member on immutable value


What is the correct way to remove or unsubscribe from service?

Answer Source

Error clearly state that peripheral.services? is not immutable content. so you cannot edit the contents in it.

You need to use

removeAllServices() - Removes all published services

and

remove(CBMutableService) - remove the specified service

Apple reference

Core bluetooth Reference