在我的应用程序中,我想检测周围磁场/电磁场的强度。我想达到的目的是测量磁场变化,以知道它是否比控制测量中的磁场更强或更弱。这是我的代码:
- (void)setupLocationManager {
self.locationManager = [[CLLocationManager alloc] init];
if ([CLLocationManager headingAvailable] == NO) {
self.locationManager = nil;
} else {
self.locationManager.headingFilter = kCLHeadingFilterNone;
self.locationManager.delegate = self;
[self.locationManager startUpdatingHeading];
}
}
// CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)heading {
CGFloat magnitude = sqrt(heading.x * heading.x + heading.y * heading.y + heading.z * heading.z);
if (self.defaultMagnitudeValue == 0.f) {
self.defaultMagnitudeValue = magnitude;
}
self.curentMagnitudeValue = magnitude;
}
幅度值反应设备周围的磁场,问题在于您需要非常接近这样一个场源。
那么,问题是:iOS应用程序是否有可能测量距离超过10-20厘米的磁场?如果可以,如何做到呢?
P.S.:我还检查了苹果的Teslameter应用程序,它几乎具有相同的代码和完全相同的问题。