我读过你可以为新的AppleTV编写应用程序。我读过它运行的iOS版本。我也读到它具有蓝牙功能。
问题,非常简单,我可以将AppleTV变成iBeacon,虽然价格非常昂贵吗? :)
答案 0 :(得分:4)
您进行iOS设备广播的方式是,您创建一个{I}对象,其中包含您要广播的UUID,主要和次要对象,调用其peripheralDataWithMeasuredPower
方法,并传递您获得此字典的字典CLBeaconRegion
startAdvertising
方法的方法。
现在,tvOS缺少CBPeripheralManager
类,但CLBeaconRegion
完成了CBPeripheralManager
方法。这意味着您应该能够生成字典以传递到iOS设备上的startAdvertising
,对其内容进行抢夺,并在您的tvOS应用程序中复制它。
事实上,人们过去一直在使用OS X Mavericks(我认为Apple在Yosemite中阻止了这一点):http://www.blendedcocoa.com/blog/2013/11/02/mavericks-as-an-ibeacon/
注意:我自己没有尝试过这种方法。完全有可能Apple在tvOS上阻止了这个技巧,就像他们在OS X上做的那样。
答案 1 :(得分:0)
看到人们“越狱”(或彻底安装Linux)Apple TV,你几乎可以安装任何东西。由于iBeacon是Apple打开的标准(并且有开源代码),我会说答案是肯定的。
答案 2 :(得分:0)
好的,我终于开始测试了这个,结果还行,有些承诺。这是细节,tvOS没有CLRegion,不会编译,所以iBeacon的官方路线不起作用。
然而,让它看到带有此代码的iBeacon;所以有希望......也许不是iBeacons,而是蓝牙......
这是我用过的BLE代码......
import Foundation
import CoreBluetooth
class BLEManager {
var centralManager : CBCentralManager!
var bleHandler : BLEHandler // delegate
required init() {
self.bleHandler = BLEHandler()
self.centralManager = CBCentralManager(delegate: self.bleHandler, queue: dispatch_get_main_queue())
}
}
class BLEHandler : NSObject, CBCentralManagerDelegate {
override init() {
super.init()
}
func centralManagerDidUpdateState(central: CBCentralManager) {
switch (central.state)
{
case .Unsupported:
print("BLE is unsupported")
case .Unauthorized:
print("BLE is unauthorized")
case .Unknown:
print("BLE is unknown")
case .Resetting:
print("BLE is reseting")
case .PoweredOff:
print("BLE is powered off")
case .PoweredOn:
print("BLE is powered on")
central.scanForPeripheralsWithServices(nil, options: nil)
default:
print("BLE default")
}
print("centralManagerDidUpdateState")
}
func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) {
print("didConnectPeripheral")
}
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
print("\(peripheral.name) : \(RSSI) dBm")
}
func centralManager(central: CBCentralManager, didFailToConnectPeripheral peripheral: CBPeripheral, error: NSError?) {
}
func peripheral(peripheral: CBPeripheral, didDiscoverServices error: NSError?) {
print("didDiscoverServices")
}
func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) {
print("didDiscoverCharacteristicsForService")
}
func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) {
print("didUpdateValueForCharacteristic")
}
func peripheral(peripheral: CBPeripheral, didUpdateNotificationStateForCharacteristic characteristic: CBCharacteristic, error: NSError?) {
print("didUpdateNotificationStateForCharacteristic")
}
func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {
print("didDisconnectPeripheral")
}
}
在viewontroller中使用这些行
var bleManager: BLEManager!
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
bleManager = BLEManager()
需要特别感谢有节奏的拳头帮助我的代码!