IOS Launch a background task to update a user's location using quick

I am a new user here, but I have used stackoverflow many times :)) ... I am an Android developer, but now I am working in an ios application using swift. I'm brand new using xcode, maybe my question is very simple for many ... Great, I really need help. I am trying to complete a backgroud task that updates the user's location every ten minutes. I need to get lat and long data and after sending this information to the API web service. I am happy with backgroud docs , all documentation and all documentation about location service . There is a lot of information, quite information, but maybe I really won information about the android, and a lot of information too, but many easy examples are also very easy for me. and overflow.site/questions/355429 / ...may help a lot.

I understand a lot of concepts, and I matched my info.plist as the documentation says, but ... how can I run a background job to get the user's location? Where should I write the background task code? What is a beginning? I have a project with three different view controllers, and I need to start the service using the button ... Thank you very much, I really need to understand the starting point of all this.

+4
source share
1 answer

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"))) {
            // on iOS8+ we need to request the location authorization ourselfs -.-

            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) {


      // This is your method for when the switch changed... put your location activation/deactivation here



      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)

    // reactivate location tracking if necessary

!

+6

All Articles