我正在尝试使用以下
来宣传BLEvar perMan: CBPeripheralManager!
let myCustomServiceUUID: CBUUID = CBUUID(string: "109F17E4-EF68-43FC-957D-502BB0EFCF46")
var myService: CBMutableService!
override func viewDidLoad() {
super.viewDidLoad()
perMan = CBPeripheralManager(delegate: self, queue: nil)
myService = CBMutableService(type: myCustomServiceUUID, primary: true)
perMan.addService(myService)
}
// Broadcast when Bluetooth is on
func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager!) {
if peripheral.state == CBPeripheralManagerState.PoweredOn {
// Start advertising over BLE
self.perMan.startAdvertising([CBAdvertisementDataServiceUUIDsKey: [myService.UUID]])
println("Adertising")
} else if peripheral.state == CBPeripheralManagerState.PoweredOff {
self.perMan.stopAdvertising()
}
}
想要发现
的外围设备import UIKit
import CoreBluetooth
class SearchViewController: UIViewController, CBCentralManagerDelegate {
var centralManager: CBCentralManager!
@IBOutlet weak var beaconsTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
centralManager = CBCentralManager(delegate: self, queue: nil)
// Listen to BLE of IPhones
let services: NSArray = ["7521105F-8937-48B7-A875-66E6FE21D714"]
centralManager.scanForPeripheralsWithServices(nil, options: nil)
}
// Found IPhone
func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) {
println("Hallo:")
println(RSSI)
}
// CBCentralManagerDelegate
func centralManagerDidUpdateState(central: CBCentralManager!) {
}
但是从不调用didDiscoverPeripheral方法。我正在测试两个IPhone5。 谁能告诉我我做错了什么?