I am currently doing the same thing as my first iOS project, which helped me with this:
Periodic updates of the iOS background location
Swift- https://github.com/voyage11/Location: https://github.com/silento/Location. voyage11 -, , , , , , " ". " ", , .
, , didUpdateLocation restartLocationUpdates - , , .
, fooobar.com/questions/34980/... stopUpdatingLocation() startUpdatingLocation() - .
, , , Android, . Iphone5 +, ( , Iphone 4S, Simulator): fooobar.com/questions/34980/....
, , , , , , ;)
P.S.: - - , 5 , - 30 . , . , , , , .
P.P.S.: Swift , Objective C-Code Swift. .
- iOS8 - :
if (self.locationManager.respondsToSelector(Selector("requestWhenInUseAuthorization"))) {
self.locationManager.requestAlwaysAuthorization()
}
"NSLocationAlwaysUsageDescription" Info.plist, .
, ;)
/edit: :
Swift, . , Main.storyboard . ToggleActionChanged, , . , , https://www.youtube.com/playlist?list=PL_4rJ_acBNMHa_RGZigG2nQI3aL1kTa4r 7- , . , , , - , . .
, . LocationDelegate.swift. . Singleton , , . github-, . , , ;)
, . , , - :
@IBAction func toggleTrackingChanged(sender: UISwitch) {
let userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setBool(sender.on, forKey: "ODLTrackingActive")
}
}
viewDidLoad:
let userDefaults = NSUserDefaults.standardUserDefaults()
var trackingActive = userDefaults.boolForKey("ODLTrackingActive")
toggleTrackingSwitch.setOn(trackingActive, animated: false)
!