Can I turn my new 4th generation AppleTV into iBeacon?

I read that you can write applications for the new AppleTV. I read that it is launching an iOS version. I also read that it has Bluetooth capabilities.

Question: very simple, can I turn my AppleTV into iBeacon, albeit very expensive? :)

+4
source share
3 answers

Well, I got it, finally, with the result, some promises. Here are the details, tvOS does not have CLRegion, will not compile, so the official route for iBeacon does not work.

Could it not be possible to see iBeacon with this code; so there is hope ... maybe not with iBeacons, but with Bluetooth ...

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")
}

}

viewcontroller

 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()

, !

0

iOS, CLBeaconRegion UUID, , , peripheralDataWithMeasuredPower , , CBPeripheralManager startAdvertising.

tvOS CLBeaconRegion, CBPeripheralManager startAdvertising. , , startAdvertising iOS, tvOS.

, OS X Mavericks ( , Apple Yosemite): http://www.blendedcocoa.com/blog/2013/11/02/mavericks-as-an-ibeacon/

. . , Apple tvOS, OS X.

+4

Seeing how people jailbreak (or directly install Linux on) an Apple TV, you can install almost anything. Since iBeacon is Apple's standard open source (and for which there is open source code), I would say the answer is yes.

0
source

Source: https://habr.com/ru/post/1615748/


All Articles