     
     /// Stop advertising the beacon.
     public func stopAdvertising() {
-        UIApplication.sharedApplication().idleTimerDisabled = false
+        UIApplication.shared.isIdleTimerDisabled = false
         if isAdvertising {
             peripheralManager.stopAdvertising()
             delegate?.virtualBeaconDidStopAdvertising(self)
         }
     }
     
-    private func startAdvertisingRegion(region: CLBeaconRegion) {
-        let advertisingData = NSDictionary(dictionary: region.peripheralDataWithMeasuredPower(nil)) as! [String : AnyObject]
+    private func startAdvertisingRegion(region: BeaconRegion) {
+        let advertisingData = NSDictionary(dictionary: region.peripheralData(withMeasuredPower: nil)) as! [String : AnyObject]
         peripheralManager.startAdvertising(advertisingData)
-        UIApplication.sharedApplication().idleTimerDisabled = true
+        UIApplication.shared.isIdleTimerDisabled = true
     }
     
     // MARK: - Peripheral Manager Delegate
     
-    public func peripheralManagerDidUpdateState(peripheralManager: CBPeripheralManager) {
-        let isBluetoothEnabled = peripheralManager.state == .PoweredOn
+    public func peripheralManagerDidUpdateState(_ peripheralManager: CBPeripheralManager) {
+        let isBluetoothEnabled = peripheralManager.state == .poweredOn
         if !isBluetoothEnabled {
             stopAdvertising()
         }
     }
     
-    public func peripheralManagerDidStartAdvertising(peripheral: CBPeripheralManager, error: NSError?) {
+    public func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {
         if error == nil {
             delegate?.virtualBeaconDidStartAdvertising(self)
         } else {
-            delegate?.virtualBeaconDidFailToStartAdvertising(self, error: error!)
+            delegate?.virtualBeaconDidFailToStartAdvertising(self, error: error! as NSError)
         }
     }
 }


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

/// VirtualBeacon allows a iOS device to act as an iBeacon.
public class VirtualBeacon: NSObject, CBPeripheralManagerDelegate {

//
// MIT License
//
// Copyright (C) 2016 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
