3

I'm new to iOS development.

I follow the tutorial from Ray Wenderlich to create a little location based AR app. However, the tutorial uses an AR Toolkit which has not been updated for a while. The UIAccelerometer it uses has already been deprecated since iOS 5, so when I try to run it on my iPhone (iOS 7.0.4), the Xcode says that there are 3 warnings, and all of them are caused by UIAccelerometer. warnings

The result it leads to is that all the marks stay at the center of the screen one above another, and the tilt does not work at all. problems

According to my research, I guess what I need to do is to use CMMotionManager instead of UIAccelerometer, but as I said before, I'm totally new to iOS development and have no idea how to replace it.

Here is the source code. I add some little functions such that you can manually add locations that are not in the Google database, but I don't think it is these functions that result in the problem.

Thanks for you help in advance!

Community
  • 1
  • 1
ylorn
  • 41
  • 1
  • 3
  • Regarding replacement of `UIAccelerometer` take a look at [Why is accelerometer:didAccelerate: deprecated in IOS5?](http://stackoverflow.com/questions/6742531/why-is-accelerometerdidaccelerate-deprecated-in-ios5/6763403#6763403) and [Simple iPhone motion detect](http://stackoverflow.com/questions/5214197/simple-iphone-motion-detect/5220796#5220796) – Kay Dec 03 '13 at 07:58
  • @Kay Thanks for your comment, but I still have no clue to get it fixed. Would you mind taking time to see the code and give me some instruction? Many many thanks! – ylorn Dec 05 '13 at 05:07

1 Answers1

2

Try this link: https://www.inkling.com/read/learning-ios-programming-alasdair-allan-2nd/chapter-9/the-core-motion-framework

I'm learning a few tidbits that translate some-what with the UIAccelerometer

i.e.

[self setAccelometerManager [UIAccelerometer sharedAccelerometer]];

could become

[self.motionManager = [[CMMotionManager alloc] init];

Setting manual update intervals like

[[self accelerometerManager] setUpdateInterval: 0.25];

you can have

self.motionManager.accelerometerUpdateInterval = 0.25;

and releasing the delegate

self.accelerometerManager.delegate = nil;

would now be

[self.motionManager stopDeviceMotionUpdates];

Also from the link, I ended up doing something like this:

motionManager = [[CMMotionManager alloc] init];

motionManager.accelerometerUpdateInterval  = 1.0/10.0; // Update at 10Hz

if (motionManager.accelerometerAvailable) {
    queue = [NSOperationQueue currentQueue];
    [motionManager startAccelerometerUpdatesToQueue:queue withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
        switch (currentOrientation) {
            case UIDeviceOrientationLandscapeLeft:
                viewAngle = atan2(accelerometerData.acceleration.x, accelerometerData.acceleration.z);
                break;
            case UIDeviceOrientationLandscapeRight:
                viewAngle = atan2(-accelerometerData.acceleration.x, accelerometerData.acceleration.z);
                break;
            case UIDeviceOrientationPortrait:
                viewAngle = atan2(accelerometerData.acceleration.y, accelerometerData.acceleration.z);
                break;
            case UIDeviceOrientationPortraitUpsideDown:
                viewAngle = atan2(-accelerometerData.acceleration.y, accelerometerData.acceleration.z);
                break;  
            default:
                break;
        }
        [self updateCenterCoordinate];
    }];

}
Ivan Vučica
  • 9,529
  • 9
  • 60
  • 111
kevinl
  • 4,194
  • 6
  • 37
  • 55
  • this is wrong, device motion is not equivalent to getting the accelerometer data. It does contain it but its not raw as the UIAccelerometer was, also it is more process intensive. CoreMotion can handle accelerometer instead. – Pochi Feb 13 '14 at 00:31
  • @Chiquis Is CMMotion not CoreMotion? I'm confused. I guess you mean to use CMAcceleration – kevinl Feb 13 '14 at 00:42