Search code examples
iosiphoneipadlocation

Why does the device stop recieving locations on iOS after two minutes gps on?


// Create a location manager object
self.locationManagerTest = [[CLLocationManager alloc] init];

// Set the delegate
self.locationManagerTest.delegate = self;

// Request location authorization
[self.locationManagerTest requestAlwaysAuthorization];

// Specify the type of activity your app is currently performing
self.locationManagerTest.activityType = CLActivityTypeOtherNavigation;

// Start location updates
[self.locationManagerTest startUpdatingLocation];

Solution

  • 1.after 2 weeks struggling on this problem finally solved it. Just needed to check apple documentation. I just needed to add two lines:

    self.locationManagerTest = [[CLLocationManager alloc] init];
    // Set the delegate
    self.locationManagerTest.delegate = self;
    // Request location authorization
    [self.locationManagerTest requestWhenInUseAuthorization];
    // Set an accuracy level. The higher, the better for energy.
    self.locationManagerTest.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
    // Enable automatic pausing
    self.locationManagerTest.pausesLocationUpdatesAutomatically = NO;
    // Specify the type of activity your app is currently performing
    self.locationManagerTest.activityType = CLActivityTypeFitness;
    // Enable background location updates
    self.locationManagerTest.allowsBackgroundLocationUpdates = YES;
    // Start location updates
    [self.locationManagerTest startUpdatingLocation];