Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. //
  2. // AppDelegate.swift
  3. // kalman
  4. //
  5. // Created by Selim Salihovic on 25/06/15.
  6. // Copyright © 2015 CityOS. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import CoreLocation
  11. import Darwin
  12.  
  13. @UIApplicationMain
  14. class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
  15.  
  16. var window: UIWindow?
  17.  
  18. var filterFactor: Double = 0.2
  19. var filteredAccuracy: Double = 0.0
  20.  
  21. let locationManager = CLLocationManager()
  22.  
  23.  
  24. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  25. locationManager.requestAlwaysAuthorization()
  26.  
  27. locationManager.delegate = self
  28.  
  29. let nest71Region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D")!, identifier: "Nest71")
  30.  
  31. locationManager.startMonitoringForRegion(nest71Region)
  32. locationManager.startRangingBeaconsInRegion(nest71Region)
  33. locationManager.requestStateForRegion(nest71Region)
  34. return true
  35. }
  36.  
  37.  
  38. func rssiToMeters(txPower: Int, rssi: Double){
  39.  
  40. //rssi = (Double(rssi) * filterFactor) + (filteredAccuracy * (1.0 - filterFactor))
  41.  
  42. let ratio: Double = rssi * 1.0 / Double(txPower)
  43.  
  44. if(ratio < 1.0){
  45. print(Double(pow(ratio, 10)))
  46. }
  47. else {
  48. let accuracy: Double = (0.89976) * pow(ratio,7.7095) + 0.111
  49. print(accuracy)
  50. }
  51.  
  52. }
  53.  
  54. func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
  55. for beacon in beacons {
  56. if beacon.major == 35214{
  57.  
  58. rssiToMeters(-65, rssi: Double(beacon.rssi))
  59.  
  60. switch beacon.proximity {
  61. case .Immediate:
  62. print("dd")
  63. default:
  64. print("stuff")
  65. }
  66.  
  67.  
  68. }
  69. }
  70. }
  71.  
  72. func applicationWillResignActive(application: UIApplication) {
  73. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  74. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
  75. }
  76.  
  77. func applicationDidEnterBackground(application: UIApplication) {
  78. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  79. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  80. }
  81.  
  82. func applicationWillEnterForeground(application: UIApplication) {
  83. // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
  84. }
  85.  
  86. func applicationDidBecomeActive(application: UIApplication) {
  87. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  88. }
  89.  
  90. func applicationWillTerminate(application: UIApplication) {
  91. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  92. }
  93.  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement