Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getLocation with timer #11

Open
kshysius opened this issue May 23, 2015 · 0 comments
Open

getLocation with timer #11

kshysius opened this issue May 23, 2015 · 0 comments

Comments

@kshysius
Copy link

Hi, I use "Handling Location Changes in the Background" examples

On simulator works fine but on device not working
I use simulator iPhone 6 iOS 8.3 and device iPhone 6 iOS 8.3
On device when i click menu button i get location but after 30 seconds i can't get location

i need realy big help...

location services enabled

i add NSTimer

code:

import UIKit
import CoreLocation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,
CLLocationManagerDelegate {

  var window: UIWindow?
  var locationManager: CLLocationManager! = nil
  var isExecutingInBackground = false

  func locationManager(manager: CLLocationManager!,
    didUpdateToLocation newLocation: CLLocation!,
    fromLocation oldLocation: CLLocation!){
      if isExecutingInBackground{
        println(newLocation);
        locationManager.stopUpdatingLocation()
      } else {
        /* We are in the foreground. Do any processing that you wish */
      }
  }

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
 {
    locationManager = CLLocationManager()
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestAlwaysAuthorization()
    locationManager.delegate = self
    locationManager.startUpdatingLocation()
    return true
  }



  func applicationDidEnterBackground(application: UIApplication) {
    isExecutingInBackground = true
    var timer = NSTimer.scheduledTimerWithTimeInterval(30, target: self, selector: Selector("update"), userInfo: nil, repeats: true)


    /* Reduce the accuracy to ease the strain on
    iOS while we are in the background */
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
  }

    func update() {
        println("test");
        locationManager.startUpdatingLocation()
    }

  func applicationWillEnterForeground(application: UIApplication) {
    isExecutingInBackground = false

    /* Now that our app is in the foreground again, let's increase the location
    detection accuracy */
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant