我正在尝试接收iPhone的标题(手机指向的方向)。
我正在尝试下面的代码,
- (void)startHeadingEvents {
if (!self.locManager) {
CLLocationManager* theManager = [[[CLLocationManager alloc] init] autorelease];
// Retain the object in a property.
self.locManager = theManager;
locManager.delegate = self;
}
// Start location services to get the true heading.
locManager.distanceFilter = 1000;
locManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locManager startUpdatingLocation];
// Start heading updates.
if ([CLLocationManager headingAvailable]) {
locManager.headingFilter = 5;
[locManager startUpdatingHeading];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading: (CLHeading *)newHeading {
if (newHeading.headingAccuracy < 0)
return;
// Use the true heading if it is valid.
CLLocationDirection theHeading = ((newHeading.trueHeading > 0) ?
newHeading.trueHeading : newHeading.magneticHeading);
self.currentHeading = theHeading;
[self updateHeadingDisplays];
}
它类似于Apple的iOS开发人员库和编程指南。 代码总是返回0到10或355到359之间的标题度。我没有得到它们之间的值。
更多,我只在iPhone 6S和iPhone 6S plus上遇到此问题。否则,这完全适用于iPhone 4S,5,5S,6,6 Plus。我的所有手机都在使用最新的iOS。