首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CoreBluetooth X码

CoreBluetooth X码
EN

Stack Overflow用户
提问于 2015-08-29 14:48:28
回答 1查看 1.7K关注 0票数 0

我遵循了正确使用CoreBluetooth的所有步骤,但Xcode一直告诉我以下几点:

方法'centralManager(:didDiscoverPeripheral:advertisementData:RSSI:)‘提供的对象-C方法'centralManager(:didDiscoverPeripheral:advertisementData:RSSI:)’与协议“CBCentralManagerDelegate”中的可选需求方法‘centralManager(:didDiscoverPeripheral:advertisementData:RSSI:)’相冲突。

代码语言:javascript
复制
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.
}

}
EN

回答 1

Stack Overflow用户

发布于 2015-11-05 01:48:47

参数由隐式展开选项(例如,CBCentralManager!)更改。对于正常的非选项(例如,CBCentralManager -带no !)。

函数签名应该如下所示(Xcode 7.1,Swift 2.1) -

代码语言:javascript
复制
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32287313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档