【发布时间】:2016-06-30 06:22:49
【问题描述】:
在我的应用中,我想检测周围磁场/电磁场的强度。我想要实现的是测量磁场变化,以了解它是否比控制测量更强或更低。这是我的代码:
- (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.:我还检查了 Apple 的 Teslameter App,它有几乎相同的代码和完全相同的问题。
【问题讨论】:
标签: ios objective-c iphone swift magnetometer