I'm not sure why this code is failing to build and the error message seems quite cryptic.
Code:
var centralManager: CBCentralManager!;
var nrf8001Peripheral: CBPeripheral!;
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// initialize centralManager
self.centralManager = CBCentralManager(delegate: self, queue: nil);
// start scanning for device
self.centralManager.scanForPeripheralsWithServices([UART_SERVICE_UUID], options:nil);
}
func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData advertisementData: [NSObject : AnyObject]!, RSSI RSSI: NSNumber) {
//print out the name of the scanned peripheral
print("Discovered \(peripheral.name)")
//print out the UUID of the scanned peripheral
print("NSUUID string \(peripheral.identifier.UUIDString)")
//stop scanning when found
self.centralManager.stopScan()
//connect when found
self.centralManager.connectPeripheral(peripheral, options:nil);
}
And the error I receive from the XCode compiler is:
"Objective-C method 'centralManager:didDiscoverPeripheral:advertisementData:RSSI:' provided by method 'centralManager(:didDiscoverPeripheral:advertisementData:RSSI:)' conflicts with optional requirement method 'centralManager(:didDiscoverPeripheral:advertisementData:RSSI:)' in protocol 'CBCentralManagerDelegate'"
From looking through the CoreBluetooth documentation it seems as if the method syntax and parameters are correct, and the optionality of the parameters is copied directly from the spec sheet: https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CBCentralManagerDelegate_Protocol/#//apple_ref/occ/intfm/CBCentralManagerDelegate/centralManager:didDiscoverPeripheral:advertisementData:RSSI:
Any help would be appreciated! Thank you
Per the comments:
- Using XCode 7 beta
When I change the function declaration to:
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData advertisementData: [NSObject : AnyObject], RSSI RSSI: NSNumber)
I still get the same build error.
My centralManagerDidUpdateState:method is
func centralManagerDidUpdateState(central: CBCentralManager) { print("centralManagerDidUpdateState:"); switch (central.state) { case .PoweredOff: print("CBCentralManagerStatePoweredOff"); case .Resetting: print("CBCentralManagerStateResetting"); case .PoweredOn: print("CBCentralManagerStatePoweredOn"); //scan for peripheral devices self.centralManager.scanForPeripheralsWithServices([UART_SERVICE_UUID], options:nil); case .Unauthorized: print("CBCentralManagerStateUnauthorized"); case .Unsupported: print("CBCentralManagerStateUnsupported"); default: print("CBCentralManagerStateUnknown"); } }