Background user location when app is terminated/suspended

后端 未结 6 2126
感情败类
感情败类 2020-12-08 20:14

I\'ve been trying to figure out how to get the user\'s location when the app is terminated like how the app Moves does it. The only way I know of doing so is with Significan

6条回答
  •  一整个雨季
    2020-12-08 20:38

    in iOS 8 they are new steps that we need to pay attention to in order make make the location fetching work. The first step is to add either one or two keys into the project’s .plist depending on the main functionality of the app. The two keys are NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription, you will then need to add a String that explains to the user why does the app needs to access his location, something among the lines of “This app uses location in the background/foreground because of A, B and C”. Each of these Strings has a corresponding authorization method that needs to be called, WhenInUse or Alway (i.e. Background).

    - (void)startStandardUpdates
    {
        // Create the location manager if this object does not
        // already have one.
        if (nil == locationManager)
            locationManager = [[CLLocationManager alloc] init];
    
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    
        // Set a movement threshold for new events.
        locationManager.distanceFilter = 500; // meters
    
        [locationManager startUpdatingLocation];
    }
    

提交回复
热议问题