我遵循了正确使用CoreBluetooth的所有步骤,但Xcode一直告诉我以下几点:
方法'centralManager(:didDiscoverPeripheral:advertisementData:RSSI:)‘提供的对象-C方法'centralManager(:didDiscoverPeripheral:advertisementData:RSSI:)’与协议“CBCentralManagerDelegate”中的可选需求方法‘centralManager(:didDiscoverPeripheral:advertisementData:RSSI:)’相冲突。
import UIKit
import CoreBluetooth
class SecondViewController: UIViewController, CBCentralManagerDelegate {
var centralManager:CBCentralManager!
var blueToothReady = false
override func viewDidLoad() {
super.viewDidLoad()
startUpCentralManager()
}
func startUpCentralManager() {
print("Initializing central manager")
centralManager = CBCentralManager(delegate: self, queue: nil)
}
func discoverDevices() {
print("discovering devices")
centralManager.scanForPeripheralsWithServices(nil, options: nil)
}
func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) {
print("Discovered \(peripheral.name)")
}
func centralManagerDidUpdateState(central: CBCentralManager) {
print("checking state")
switch (central.state) {
case .PoweredOff:
print("CoreBluetooth BLE hardware is powered off")
case .PoweredOn:
print("CoreBluetooth BLE hardware is powered on and ready")
blueToothReady = true;
case .Resetting:
print("CoreBluetooth BLE hardware is resetting")
case .Unauthorized:
print("CoreBluetooth BLE state is unauthorized")
case .Unknown:
print("CoreBluetooth BLE state is unknown");
case .Unsupported:
print("CoreBluetooth BLE hardware is unsupported on this platform");
}
if blueToothReady {
discoverDevices()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}发布于 2015-11-05 01:48:47
参数由隐式展开选项(例如,CBCentralManager!)更改。对于正常的非选项(例如,CBCentralManager -带no !)。
函数签名应该如下所示(Xcode 7.1,Swift 2.1) -
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {https://stackoverflow.com/questions/32287313
复制相似问题