氣壓計實踐上叫測高儀,由於氣壓次要與海拔高度有關
氣壓計的硬件在iPhpne外部,次要是檢測大氣壓強(kPa)的,而大氣壓強由於海拔高度有關 不是檢測風速的,不要以為對著iPhone吹氣,氣壓值就會變化傳感器不屬於隱私功用,不需求受權
氣壓計是iPhone6開端參加的硬件,不支持6以前的機型
運用氣壓計相當復雜
#import "ViewController.h"
//傳感器框架
#import <CoreMotion/CoreMotion.h>
@interface ViewController ()
@property(nonatomic,strong)CMAltimeter *altimeter;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//1.創立氣壓計(測高儀),這裡要用全局變量,不然會被釋放
self.altimeter = [[CMAltimeter alloc] init];
//2.檢測以後設備能否可用(iphone6機型之後新增)
if([CMAltimeter isRelativeAltitudeAvailable])
{
//3.開端檢測氣壓
[self.altimeter startRelativeAltitudeUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAltitudeData * _Nullable altitudeData, NSError * _Nullable error) {
NSLog(@"高度:%0.2f m 氣壓值:%0.2f kPa",[altitudeData.relativeAltitude floatValue],[altitudeData.pressure floatValue]);
}];
}
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
【iOS傳感器之氣壓計的運用】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!