-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Known issue with CBCentralManager initialization #610
Comments
Hey @pilmen, First of all, thank you for that PR. The reason I haven't merged it yet is because it would introduce dependency on CoreBluetooth which most Bond users don't use. I'm still looking into ways to resolve that. To answer this question: Could you have a dummy delegate during the initialization that implements that method? |
You probably want something like this: extension ReactiveExtensions where Base: NSObject {
public static func makeWithProtocolProxy<P>(for `protocol`: Protocol, keyPath: ReferenceWritableKeyPath<Base, P?>, make: @escaping (P) -> Base) -> Base {
let controller = OptionalKeyPathProtocolProxyPropertyController(object: nil, keyPath: keyPath)
let protocolProxy = ProtocolProxy(protocol: `protocol`, propertyController: controller)
let object = make(protocolProxy as! P)
controller._object = object
object.protocolProxies[controller] = protocolProxy
return object
}
} so that you can do let manager = CBCentralManager.reactive.makeWithProtocolProxy(for: CBCentralManagerDelegate.self, keyPath: \.delegate) { (delegate) -> CBCentralManager in
return CBCentralManager(delegate: delegate, queue: nil, options: [:])
} Note that this will not work out of the box because |
Hey @srdanrasic , yes dummy delegate works in this case. I'll try to work with the approach from your last message. I'm not sure either if this extension should to be a part of main Bond Framework. Thanks for your help and great job around this framework. |
I will close this for now. Feel free to reopen if there will be more stuff on this. |
Sure, I didn't have much time to look into this. If I'll be have solution for this I let you know. |
@ #602 When try to init CBCentralManager with option CBCentralManagerOptionRestoreIdentifierKey (CBCentralManager(delegate: <CBCentralManagerDelegate?>, queue: <DispatchQueue?>, options: <[String : Any]?>)) you getting crash:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<CBCentralManager: 0x600002a73c40> has provided a restore identifier but the delegate doesn't implement the centralManager:willRestoreState: method'
I believe it happens because at the moment of initialization CBCentralManager calling delegate method centralManager:willRestoreState: if this key present. But we don't actually have delegate passed as a parameter at time of initialization. @tonyarnold @srdanrasic Do you have any suggestions how can I fix it? Thanks in advance.
The text was updated successfully, but these errors were encountered: