문제

I have read Apple's documentation on CMMotion and everything that needs to be done in order to NSLog accelerometer data appears to be done in my app. However, when I run my app and flip the screen there is no data returned from the Accelerometer. I have no runtime errors. Here is my code:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    ad = [[CMMotionManager alloc] init];
    //[ad startDeviceMotionUpdates];
    [ad startAccelerometerUpdates];

    //Returns Null
    NSLog(@"Accelerometer Data %@", ad.accelerometerData);

    BOOL accelerometerAvailable = ad.isAccelerometerAvailable?YES:NO;

    // Returns false, else statement is logged
    if(accelerometerAvailable) {
    NSLog(@"I guess it is...");
    } else {
    NSLog(@"I guess it is not...");
      }

    [ad startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]     withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
    NSLog(@"Your accelerometer data is: %@", accelerometerData.acceleration);
}];

 }

I tried adding this code to another app of mine that returns data on a time interval to make sure that the reason I was not getting data was because viewDidLoad is only called once. I still got nothing.

도움이 되었습니까?

해결책

My mistake here. This issue stems from me using the iOS simulator to run my application. Apparently, the accelerometer does not work in it. I assumed that because shake, and rotate events were allowed that they were for the accelerometer. However, they are just for the repositioning of the screen, which is independent of the accelerometer. It would help if Apple included this in its documentation.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top