cocos2d CCLayer.m UIAccelerometer is deprecated warning - c++

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

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.

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.

Related

Alternative of CreateVideoSource() in webrtc

Hi all I had seen one webrtc old source code which has this method called CreateVideoSource() for adding streams after an CreateAudioTrack() call.
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source =
peer_connection_factory_->CreateVideoSource(std::unique_ptr<cricket::VideoCapturer>(
media_source->GetVideoCapturer()),
NULL);
What's happening is whenever I try to build it gives an error for the above CreateVideoSource() that it is undefined. And the reason behind that is the latest webrtc-checkout has deprecated this.
So my question is, I wanted to know the alternative which they have introduced after deprecating this method. So can anyone tell me what the alternate approach is.
Okay, Finally I was able to come up with an alternative(i.e the current implementation of libwebrtc) after looking into bundle examples and tests.
Line 71 is a good point to start

Swift 3 - AWS iOS 'EXC_BAD_INSTRUCTION' Error

After converting over to Swift 3, my AWS iOS App now crashes when being run.
Has anyone seen anything similar after converting over to Swift 3?
Its crashing because you are doing a few things here:
trying to return a method call (which I don't think is possible - but I've never tried it)
application: didFinishLaunching should only ever return true because it's a boolean function as the name suggests. So the return value should be true. If you'd like to override application: didFinishLaunching you can declare that later in your AppDelegate
So here's what you can do... Try deleting the method and slowly type it back until Xcode auto-completes it for you. That will allow you to see what has been depreciated, or what other methods might be useful, also if you haven't yet hit Command + Shift + K to run a clean on your project. Xcode 8 and Swift 3 might have altered a few more things you aren't aware of.
launchOptions is an optional parameter. Doing a forced unwrap with the ! will crash if the value is nil, which it usually is.

'itemFromNormalSprite:selectedSprite:target:selector:' is deprecated

Why am I getting this warning and how can I fix it?
I'm using Kobold2D v2.1.0 (Uses cocos2d-iphone v2.1 and OpenGL ES 2.0)
My code:
CCMenuItemSprite *flareButton = [CCMenuItemSprite itemFromNormalSprite:flareSprite selectedSprite:flareSelectedSprite target:self selector:#selector(flareSelected)];
Can you also tell me how I can avoid these deprecations in the future by looking at a reference of any kind. Thanks
Look into ccDeprecated.m - you'll find all deprecated methods there as well as the correct (changed) way to use the function.
Deprecated in cocos2d means in almost all cases that the name of the function, the parameter list or its location have changed. You can also disable deprecation warnings in Build Settings and just ignore it for at least until the next major cocos2d update.
You can try with:
CCMenuItemSprite *flareButton = [CCMenuItemSprite itemWithNormalSprite:flareSprite selectedSprite:flareSprite target:self selector:#selector(flareSelected)];
Change From to With on itemFromNormalSprite: will be itemWithNormalSprite:

Cocos2D iPhone Extensions v0.2.1: CCMenuAdvanced warning: CCMenu may not respond to initWithItems:vaList: Should I be concerned?

Looked in the CCMenu.h and it looks like it responds to the exact method Xcode (4.5.2) is saying it doesn't respond to. I've tried overriding the method and extending CCMenu, but it always throws the same message.
When I build and run my project, it seems to work fine. Should I ignore this warning and continue with my game? Another question: Is there a simple way to 'update' this code to a non-deprecated or outdated method? Here's the cocos2d-iphone-extensions version I'm using. Also, it's cocos2d 2.1.
The error is generated on line 76 of the .m file.
CCMenuAdvanced.h:
https://github.com/cocos2d/cocos2d-iphone-extensions/blob/master/Extensions/CCMenuAdvanced/CCMenuAdvanced.h
CCMenuAdvanced.m:
https://github.com/cocos2d/cocos2d-iphone-extensions/blob/master/Extensions/CCMenuAdvanced/CCMenuAdvanced.m
You are getting this warning because -(id) initWithItems: (CCMenuItem*) item vaList: (va_list) args is not present in the header file (CCMenuAdvanced.h).
You need to use + (id) menuWithItems: (CCMenuItem*) firstItem vaList: (va_list) args; from CCMenu (superclass of CCMenuAdvanced).

Can Xcode recognize class variables in C++

For example, this simple class:
class Test
{
public:
Test();
int _public;
};
Test::Test()
{
this->_public = 0; // Shows _public in color
_public = 5; // Stay White
}
This seem to work for Cocoa apps, but not on C++.
Just to be a bit clearer from my original post, this DOES compile and run exactly as expected.
The only impact from Cocoa to C++ is the syntax highlighting. I know that this is only a dev "feature" and shouldn't in any case be seen as a "must have" from the compiler it's just that since it's working for Cocoa why not C++ right ? Give developers a nice feature and they'll want instantly even more :)
Is a fix available ?
You are right, in Xcode 3 it doesn't work. Xcode 4 however does fix this, as it uses a much deeper integration of the compiler. It's not out yet (if you have a developer account you can download a preview), but it will probably be released soon, patience ;)