 
 /// Delegate of the VirtualBeacon class.
 public protocol VirtualBeaconDelegate : class {
-    func virtualBeaconDidStartAdvertising(virtualBeacon: VirtualBeacon)
-    func virtualBeaconDidFailToStartAdvertising(virtualBeacon: VirtualBeacon, error: NSError)
-    func virtualBeaconDidFailToStartAdvertisingDueToBluetoothNotEnabled(virtualBeacon: VirtualBeacon)
-    func virtualBeaconDidStopAdvertising(virtualBeacon: VirtualBeacon)
+    func virtualBeaconBluetoothPoweredOn(_ virtualVeacon: VirtualBeacon)
+    func virtualBeaconDidStartAdvertising(_ virtualBeacon: VirtualBeacon)
+    func virtualBeaconDidFailToStartAdvertising(_ virtualBeacon: VirtualBeacon, error: NSError)
+    func virtualBeaconDidFailToStartAdvertisingDueToBluetoothNotEnabled(_ virtualBeacon: VirtualBeacon)
+    func virtualBeaconDidStopAdvertising(_ virtualBeacon: VirtualBeacon)
 }
+
+#if os(tvOS)
+    private struct BeaconRegion {
+        let proximityUUID: NSUUID
+        let major: UInt16
+        let minor: UInt16
+        let identifier: String
+        
+        init(proximityUUID: NSUUID, major: UInt16, minor: UInt16, identifier: String) {
+            self.proximityUUID = proximityUUID
+            self.major = major
+            self.minor = minor
+            self.identifier = identifier
+        }
+        
+        func peripheralData(withMeasuredPower power: Int8?) -> [String: AnyObject] {
+            let iBeaconKey = "kCBAdvDataAppleBeaconKey"
+            
+            let data = NSMutableData(capacity: 21)!
+            var uuidBytes = [UInt8](repeating: 0, count: 16)
+            proximityUUID.getBytes(&uuidBytes)
+            data.append(uuidBytes, length: 16)
+            var majorValue = CFSwapInt16(major)
+            data.append(&majorValue, length: 2)
+            var minorValue = CFSwapInt16(minor)
+            data.append(&minorValue, length: 2)
+            var powerValue: Int8 = power ?? -59
+            data.append(&powerValue, length: 1)
+            
+            return [iBeaconKey: data]
+        }
+    }
+#else
+    typealias BeaconRegion = CLBeaconRegion
+#endif
 
 /// VirtualBeacon allows a iOS device to act as an iBeacon.
 public class VirtualBeacon: NSObject, CBPeripheralManagerDelegate {

//
// Copyright © 2015 Apparata AB. All rights reserved.
//
// MIT License
//
// Copyright (C) 2015 by Apparata AB
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

    ///     - minor: The least significant value of the beacon.
    ///
    /// - SeeAlso: CoreLocation.CLBeacon
    public func startAdvertising(uuid: UUID, major: CLBeaconMajorValue, minor: CLBeaconMinorValue) {
        let isBluetoothEnabled = peripheralManager.state == .poweredOn
        if isBluetoothEnabled {
#if os(tvOS)
    region = BeaconRegion(proximityUUID: uuid as NSUUID, major: major, minor: minor, identifier: VirtualBeacon.regionIdentifier)
#else
    region = BeaconRegion(proximityUUID: uuid, major: major, minor: minor, identifier: VirtualBeacon.regionIdentifier)
#endif
            if isAdvertising {
                peripheralManager.stopAdvertising()
            }
            startAdvertisingRegion(region: region)
        } else {
            delegate?.virtualBeaconDidFailToStartAdvertisingDueToBluetoothNotEnabled(self)
        }
