How to make cocos2d v1.0.1 support Retina? - ios

I have to work with a project made by another developer. This project uses cocos2d v1.0.1. And the problem is it doesn't support Retina display. When i go into [director enableRetinaDisplay:YES]; method i see that it returns NO on the line:
if (! [openGLView_ respondsToSelector:#selector(setContentScaleFactor:)])
return NO;
So the question is - is it possible somehow to make this version of cocos2d support Retina?
EDIT: I'm running it in iOS 6.1 simulator. Retina simulator.

! is negation operator. !condition evaluates to true if and only if condition is false.
return NO; line will only be executed if openGLView_ does not respond to setContentScaleFactor:.
UIView's contentScaleFactor property is available in iOS 4.0 and later. Checking for availability of the setter of this property is a way to check if device itself is capable of retina. If openGLView_ does not respond to setContentScaleFactor:, then this device doesn't have retina, and this is why CCDirector's enableRetinaDisplay returns NO.
If you are running your code on device and getting NO here, then this device doesn't have retina. If you are running it on simulator, make sure that it's simulating at least iOS 4.0. To get retina device simulator, select any of retina configurations in Hardware->Device menu.
Edit:
Is openGLView_ nil? In Objective C you can call any method on nil, and it will do nothing and return nil (zero, NULL, NO). You have to create an EAGLView and set it as CCDirector's OpenGL view before enabling retina display.

Related

Cannot rotate interface orientation to portrait upside down on iPhone X

We have an app which makes use of an accessory connected to the audio jack(or lightning port in iPhone7 or later).It needs to be run in certain orientations, depending on iOS device.
There are currently no issues setting device orientation in either simulator or actual device for any iPhone, except the iPhoneX simulator.
Current code for setting orientation:
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
//device checks omitted
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
Target settings with orientations enabled
Stack trace:
TF uncaught exception reason : Supported orientations has no common orientation with the application, and [RootNavigationController shouldAutorotate] is returning YES
2017-10-05 09:35:02.692945+0200 [65045:74145368] *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [RootNavigationController shouldAutorotate] is returning YES'
This is working on iPhone5, iPhone6, iPhone6+, iPhone7 and iPhone7+ devices and iPhone8 simulators. It doesn't seem to be an iOS11 issue either as my iPhone7 is currently running iOS11. The only device I'm currently having issues with is the iPhoneX simulator.
It appears that the iPhone X will not support upside-down orientation; see https://forums.developer.apple.com/message/268015. An Apple staffer says, "It is by design. We're getting documentation updated in a future release to reflect that."
You still get the orientation change notification, at least in the sim, but as you found, Bad Things may happen if you act on it. In my case I don't get an exception, but my UI doesn't redraw properly.
I'm adding code to detect an upside-down iPhone X and prevent the UI redraw; it works in the sim, and we'll have to wait and see if it'll work on the real device (fortunately my use case for upside-down only involves a headphone-jack device, so loss of upside-down on iPhone X isn't a big deal for me).
The upshot is that those of us using lighting port Sensors That Want To Be On Top will not be able to offer iPhone X users the same usability as on "lesser" iPhones, at least not without some seriously tedious UI jiggery-pokery involving lots of affine transforms to rotate and/or flip elements to appear upside-down while still conforming to what the phone thinks it's doing. Sigh.

Snapshot fails on some iOS devices

I've got an app where I have a GLKit View Controller. I need to get a snapshot of the GL view.
I'm using:
glImage = [(GLKView *)self.view snapshot] ;
where glImage is a UIImage.
It works fine every time on my iPhone 5s (iOS 8.1), but just gives a blank image on my iPad Mini (iOS 7.1) and my iPhone 4s (also 7.1). The image is exactly the size I'd expect but blank.
This feature has been in place since iOS5 so it doesn't look like an OS issue.
Why doesn't this work? Is it a processing issue?
Edit - I upgraded the iPad to iOS8.1 and the problem remains so definitely not an OS issue.
It's not exact answer but you may consider using this method:
In short words it attaches CVPixelBuffer to OpenGL Framebuffer which allows it
to be read quickly by CPU. I am using it to capture video and never had problems
with it. Also it may be quicker then snapshot since it does not require your view
to be redrawn.

Ios app strange rotation behaviour after iOS 8 SDK update

I've been developing an iPad app which was working fine until i updated my Xcode to version 6 and my iPad to iOS 8.The problem i am encountering now is that when i change the orientation of my iPad i can catch the event but the views do not rotate accordingly.To be specific in my iPad with iOS 7 app rotates itself size of the views stay the same; for example if i start the app in portrait mode and change rotation to landscape there is a space on the right side of the uiview.In my iPad with IOS 8 views do not even rotate itself and stay the same all the time.I'm not using auto layout and app used to work like charm before IOS 8 SDK release.I need your help on finding articles and cause of the problems.Thanks in advance
probably the cause of problem is this line but i need to have this because otherwise my app won't release uiwebview from memory.
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
self.view.window.rootViewController=self;
}
Rotation handling has changed in iOS 8. Methods such as willRotateToInterfaceOrientation:duration: and didRotateToInterfaceOrientation: are now deprecated and replaced by viewWillTransitionToSize:withTransitionCoordinator:. Depending on how you're handling rotations in your app, you may have to make changes in your code to adapt to the new methods. Check chapter "Handling view rotation" in the UIViewController reference docs

iPad app not laying out properly

I have an iPad app that I've inherited the code for.
I'm relatively new to iPad development, so please bear with me...
The app was compiled off-site by a contractor in 2010. Since then, my company has been acquired and we're in the process of rebranding. My seemingly simple task is to replace our logo in this app with a new logo. It should take a few minutes - just drop a new logo into the code, compile, and bam! Done.
There's a problem with compiling the code...the working app launches in landscape mode and fills the entire screen with its interface. When I compile the app in the simulator or run it on my iPad (connected to my mac via USB cable), the screen launches in landscape mode, but the view is in portrait mode. In intermittent places throughout the app, the views switch from landscape to portrait layout.
This is driving me nuts because I don't even know what to look for. I see some references to shouldAutoRotateToInterfaceOrientation - I think that's been deprecated. Could that be causing the problem?
I know a LOT has changed since 2010. I'm currently running the latest version of XCode on a new mac. (From what I understand, my predecessor never actually compiled the app here, but relied totally on the contractor...from what I can see, this may be a problem that's been there all along, but nobody was aware of)
UPDATE
I have an older mac (with an older version of XCode) to test with. I've moved the app code onto the older mac, changed a few settings, and it works correctly.
I've also noticed the layout isn't quite correct on ANY app I create on my new mac. For example, dropping a button near the top of the form winds up scrolled off the top of the app, so it's not even visible.
Is there a setting in XCode that defines this behavior?
In iOS 6.0 check for view controller orientations condition is changed..
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return YES;
}
else
{
return NO;
}
}

Xcode debug warning about two-stage rotation animation

My iPad app outputs the following warning in xcode debugger below using (gcc).
It's very frustrating because I don't know how to debug it.
Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
I do use following method for rotation changes
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration{
//with conditional statement like
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
//change images for portrait, redisplay any visible popovers
}else{
//change images for landscape, redisplay any visible popovers
}
I'm not using any older two stage methods.
The app does use a root tabbarController with two viewControllers and one navigationController tabs in it.
Any help would be great.
May not be a real warning or an older version byproduct as I am not getting warning when I use a different mac with another iPad all running the latest xcode 4.3.3 and iPad iOS 5.1 (warning was on xcode 4.2 with iOS 4.3)
Also note these warning were only appearing when running on the device itself and not in simulator.
Hope that helps someone else.

Resources