// 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];

最佳答案

1.经过2个星期的努力,这个问题终于解决了。只需检查Apple文档即可。我只需要添加两行:

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];

关于ios - 两分钟gps开启后,为什么设备会停止在iOS上接收位置信息?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46948311/

10-08 23:29