开发者

turning off iPhone accelerometer while not using it

At a spot in my game there is a brief use of the accelerometer. I use this code:

UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = 1.0f/60.0f;

to start the accelerometer and then update it using:

- (void)accelerometer:(UIAccelerometer *)accellerometer didAccelerate:(UIAcceleration *)acceleration {

    if (whichLevel == 24) {
        //Blah blah blah, using accelerometer 
    } else {
        //Turn accelerometer off somehow?
    }
//I have found out using this:
NSLog(@"Accelerometer being used");
//That the accelerometer is being used after I start it in the game.
}

And of course, in the .h I put a This sort of code is used in more than a few tutorials-- But my point is, this is only used for a brief period, and I would like a way to turn it off while I am not 开发者_如何学运维using it. (Which none of the tutorials show you how to do)

Apple seems to say here: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MotionEvents/MotionEvents.html -- that you should use

[motionManager stopAccelerometerUpdates];

but apparently you have to set it up that way in order to stop it that way. Do I have to change how I set it up in order to end it?? Or can I end it using what I have?

Thanks in advance,

The Me


Setting the accelerometer’s delegate to nil should let it know that you don’t need its updates anymore. It still might not get powered off entirely—the system watches it to deliver orientation-change events, for instance—but your app won’t be responsible for that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜