嗨,我有我的类传感器,其中有gps,陀螺仪,加速度计,我想从nsoperationqueue发送委托中的数据:

@protocol SensorsDelegate <NSObject>
@optional
- (void)motionManagerDidAccelerateData:(CMAccelerometerData *)accelerometerData;
@end


- (void)startAccelerometr
{
    if (motionManager.accelerometerAvailable) {

        self.motionManager.accelerometerUpdateInterval = 1.0/10.0;
        [self.motionManager startAccelerometerUpdatesToQueue:self.operationQueue
          withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
            if (error) {
                [motionManager stopAccelerometerUpdates];
            }
            else {
                [self.delegate motionManagerDidAccelerateData:accelerometerData];
            }
        }];
    }
}


如何将数据发送到主线程中的委托?还是发送加速器数据?

最佳答案

您是否尝试过使用

[self.delegate performSelectorOnMainThread:@selector(motionManagerDidAccelerateData:) withObject:accelerometerData waitUntilDone:NO];

10-07 21:29