iOS 9 Stops Periodic Background Processing Using Location Information

Asked 2 years ago, Updated 2 years ago, 47 views

I am trying to upload my location information to the server by performing periodic background processing using location information on iOS 9.I have three questions.

I have attached the program I wrote for your reference.We have removed functions that we do not think are necessary.
It doesn't have to be a single answer to all questions.If you know a part of it, please let me know.

<Additionally, this is what I set up (+to use location information) to run in the background>
·Check Location updates in Capabilityes Background Modes
·In info.plist
 Configuring NSLocationAlwaysUsageDescription
 Configuring App registers for location updates in Required background modes->Item0
·Import CoreLocation.framework

import UIKit
import CoreLocation

@UIAapplicationMain
classAppDelegate:UIResponder, UIApplicationDelegate, CLLocationManagerDelegate{

    var window —UIWindow?

    varkeido —String!
    varido —String!    
    varlm —CLLocationManager!=nil
    var longitude —CLLocationDegrees!
    var latitude —CLLocationDegrees!

    func application(application:UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) ->Bool{
        longitude=CLLocationDegrees()
        latitude=CLLocationDegrees()
        keido=String(stringInterpolationSegment:longitude)
        ido=String(stringInterpolationSegment:latitude)

        lm = CLLocationManager()
        lm.delegate = self
        lm.requestAlwaysAuthorization()
        lm.desiredAccuracy = kCLLocationAccuracyHundredMeters // 100m
        lm. dist, including, quote above for more    ) language oriented channel dedicated to meters away /   100 Once information update
        lm. pause XSetLocaleModifiers version in access : (A 20 % if sited in SEZ) Update a part usualy Riley   of suppressing low update frequency   stop // = false     (false )
        lm.startUpdatingLocation()
        return true
    }

    //   location updates
    func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation){
        longitude = newLocation.coordinate.longitude
        latitude = newLocation.coordinate.latitude
        keido = String(stringInterpolationSegment: longitude)
        ido = String(stringInterpolationSegment: latitude)
        let myUrl:NSURL = NSURL(string: NSString(format:"http://(*mask*)/location/locationget.php?id=(mask)&longitude=%@&latitude=%@",String(stringInterpolationSegment: longitude),String(stringInterpolationSegment: latitude)) as String)!
        let myRequest:NSURLRequest  = NSURLRequest(URL: myUrl)
        NSURLConnection.sendAsynchronousRequest(myRequest, queue: NSOperationQueue.mainQueue(), completionHandler: self.getHttp)
    }

    func getHttp(res:NSURLResponse?, data:NSData?, error:NSError?){
        // Convert returned data into a string.
        let myData: NSSstring = NSSstring (data:data!, encoding:NSUTF8StringEncoding)!
        NSLog (myData as String)
    }

    funclocationManager(manager:CLLocationManager, didFailWithError:NSError) {
        NSLog ("Error")
    }
}

swift

2022-09-30 19:38

1 Answers

I don't know if it will lead to a resolution, but I will write it in the form of an answer.

1. Why does the periodic background process for location updates stop? (I don't know when it stopped.)
Notification of location updates is stopped due to various factors.For more information, please refer to the official documentation as much as possible.
Location and Map Programming Guide
Location and Maps Programming Guide
(The Japanese version of the timestamp is quite old, so please use the English version if possible.)
iOS Application Programming Guide
App Programming Guide for iOS
(It is described in an independent chapter on Running the Background, and it is also described in Tracking User Locations.Other chapters also provide relevant information.)

I don't have a detailed checklist, so it's a rough description, but

  • Applications in the background may be suspended from the system at any time
    (Standard Location Service does not start applications that have stopped.)
  • If you make the required declaration, it shouldn't stop easily, so you need to review the various settings again
  • NSURLConnection is not guaranteed to work in the background

That's what I said.

As for 2 and 3, there is nothing to do with Singletonization and background execution, so I can't say anything unless you provide the context before and after the comments you are based on.


2022-09-30 19:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.