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

时间:2017-10-26 07:33:28

标签: ios iphone ipad location

// 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 个答案:

答案 0 :(得分:2)

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)

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