DCDC DCDC - 1 year ago 60
iOS Question

How to remove/unsubscribe from service in core bluetooth?

I try to achieve it in the following way:


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


remove(CBMutableService) - remove the specified service

Apple reference

Core bluetooth Reference