4

I'm not actually using the accelerometer in my app, but this warning is the only one I get during the build process. I'd like to correct it or eliminate it. This warning directs me to the CCLayer.m cocos2d original files. There a 4 warnings about the UIAccelerometer deprecations.

(LINES 91 & 93 is where the warnings start) ! UIAccelerometer is deprecated in iOS 5.0 - UIAccelerometer has been replaced by the CoreMotion framework

    85:-(void) setIsAccelerometerEnabled:(BOOL)enabled
    86:{
    87: if( enabled != isAccelerometerEnabled_ ) {
    88:     isAccelerometerEnabled_ = enabled;
    89:     if( isRunning_ ) {
    90:         if( enabled )
    91:             [[UIAccelerometer sharedAccelerometer] setDelegate:self];
    92:         else
    93:             [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
    94:     }
    95: }
    96:}

When I dig deeper into the warnings it brings me deeper into the UIAccelerometer.h UIKit

Have others had this problem? How to deal with it? Should I just ignore it? Any suggestions would be greatly appreciated. Thanks, Justin

4

2 回答 2

5

Cocos2d-iphone as of version 2.1 has not been updated to be fully compatible with iOS 7.

As far as accelerometer is concerned you can safely comment out all references to / uses of UIAccelerometer. If you do need accelerometer in your app use CMMotionManager.

Alternatively you can use Kobold2D whose github version includes the necessary fixes to cocos2d-iphone.

于 2013-10-23T21:50:27.137 回答
0

I'm personally not the biggest fan of how Kobold2d "solved" the issue. They're wrapping the code with pragmas that disable the warning. Personally, I'd prefer to offer that it's better to replace the deprecated code with CoreMotion class.

To maintain the usability of a singleton class; use this answer: How do I initialize CMMotionManager globaly to be used by different classes? then in CCLayer.h at line 32 import MotionManagerSingleton.h Next in CCLayer.m replace everything that looks like UIAccelerometer with the new call to this class and it works quite well.

于 2014-03-16T22:17:14.923 回答