为什么设备在两分钟gps开启后停止接收iOS上的位置?

时间:2022-03-14 02:54:35
// 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];

2 个解决方案

#1


1  

in Capabilities/Background modes/ turn on location updates and info.plist add this key "Privacy - Location Always Usage Description" hope this helped

在功能/背景模式/打开位置更新和info.plist添加此密钥“隐私 - 位置始终使用说明”希望这有助于

#2


1  

1.after 2 weeks struggling on this problem finally solve it just needed to go to apple documentation. I just needed to add two lines only:

1.经过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];

#1


1  

in Capabilities/Background modes/ turn on location updates and info.plist add this key "Privacy - Location Always Usage Description" hope this helped

在功能/背景模式/打开位置更新和info.plist添加此密钥“隐私 - 位置始终使用说明”希望这有助于

#2


1  

1.after 2 weeks struggling on this problem finally solve it just needed to go to apple documentation. I just needed to add two lines only:

1.经过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];