为什么设备在开启 GPS 两分钟后停止接收 iOS 上的位置信息?
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];
在Capabilities/Background模式下/打开位置更新
并且 info.plist 添加此密钥 "Privacy - Location Always Usage Description"
希望这有帮助
1.after这个问题折腾了2周终于解决了。只需要检查苹果文档。我只需要添加两行:
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];
// 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];
在Capabilities/Background模式下/打开位置更新 并且 info.plist 添加此密钥 "Privacy - Location Always Usage Description" 希望这有帮助
1.after这个问题折腾了2周终于解决了。只需要检查苹果文档。我只需要添加两行:
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];