我想知道如何创建高度增加时的通知和高度降低时的通知。我已经试过这段代码了,但我不知道下一步该怎么做。
- (CMAltimeter *)altimeter {
if (!_altimeter) {
_altimeter = [[CMAltimeter alloc]init];
}
if ([CMAltimeter isRelativeAltitudeAvailable]) {
CMAltimeter* altimeter = [[CMAltimeter alloc] init];
NSOperationQueue* queue = [[NSOperationQueue alloc] init];
[altimeter startRelativeAltitudeUpdatesToQueue:queue withHandler:^(CMAltitudeData* altitudeData, NSError* error) {
}];
}
return _altimeter;
}发布于 2018-03-21 07:02:33
每次有更新时,您都会取出数据:
[altimeter startRelativeAltitudeUpdatesToQueue:queue
withHandler:^(CMAltitudeData* altitudeData, NSError* error)
{
// Put your data-handling code here -- for example,
// if your display has an element userRelAltitude
// that displays text:
float relAltitude;
relAltitude = altitudeData.relativeAltitude.floatValue;
self.userRelAltitude.text = [NSString stringWithFormat:@"%.0f m", relAltitude];
}];然后,您可以将每个值与前一个值进行比较,看看它是在增加还是在减少,并显示相应的通知。
https://stackoverflow.com/questions/49393832
复制相似问题