Advertisement Stops in Foreground Mode

I've created a Bluetooth peripheral manager with one service and one characteristic. This peripheral manager has been created with CBPeripheralManagerOptionRestoreIdentifierKeyoption to have restoration state. I've also set up required settings for Bluetooth LE services in background mode.


Finally everything works well in foreground and background except advertising. Actually I know I can't advertise in background mode based on Apple rules. But my problem is advertising in foreground mode which stops in some cases and starts again strangely. So when it happens.


Suppose I install my app to my phone using Xcode and app starts advertising. So far so good. Now I run my app through Xcode one more time. In this case app runs again in foreground but when I check the advertising signal with LightBlue, it shows that there is no advertisement data from my app. At the same time if I check programmatically the isAdvertisingproperty shows the app is advertising, but I'm sure it is not. Now if I call stopAdvertising() or startAdvertising() functions, it will not help and there won't be any data from my app in the advertisement of the phone.


Another strange subject is that while this problem is occurring, if I press home button and send the app to the background mode and then bring it to foreground mode using app switcher, advertising data starts again!!!


You might say that it's only a rare case which happens only during app installation by Xcode so it's not a serious problem. But there is also another situation that this problem happens. That's when the iOS terminates the app in background mode due to memory pressure issues. After that termination, if I run the app through app switcher this problem will occur again.


Note: If I don't useCBPeripheralManagerOptionRestoreIdentifierKey option in creating peripheral manager, the problem won't be happed at all.