简体   繁体   中英

iOS update location after kill app from Background

In my project, I want to track user location. For that i want to update user current location based on location accuracy(for High-> 15 min and Low -> 1 hour). When application run or in background than I can update location but after kill application from background, can't update location. I used timer to call it but after kill app(from background), it's not work.

So now what i do to update location based on location accuracy if user not run app in background also.

Please give any suggestion.

CoreLocation has 2 permisson:

  1. One is for when the user use the app.
  2. The second is updating location always even if it is not in used.

Use the second one, that's what GPS use for instance. But if you kill the app that is a going to stop updating location.

You need to add the NSLocationAlwaysUsage keys to your apps info.plist and then request permission when you wish to start monitoring.

Make sure you give a good description of why you want to always monitor bc I feel that really helps conversion rates.

    locationManager = [[CLLocationManager alloc] init];
    #define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

    if(IS_OS_8_OR_LATER)
    {
        [locationManager requestWhenInUseAuthorization];
    }

    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; //whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;

    [locationManager startUpdatingLocation];

that code user location update only forground app running but not background run

        if(IS_OS_8_OR_LATER)
        {
            [locationManager requestWhenInUseAuthorization];
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM