cocos2dx OpenGL error 0x0506 when dismissing UIViewController - c++

I've run into very difficult issue. In the Cocos2d-x game i'm working upon currently (it's main part is written by another developer i'm just finishing it, and by now it is supposed to work on iOS only so i don't care about all the Android related stuff ) i need to use UIViewController. I present it and dismiss in a very usual way:
present:
SDMoreAppsViewController *vc = [[SDMoreAppsViewController new] autorelease];
[viewController presentViewController:vc animated:NO completion:nil];// viewController is UIWindow root view controller
dismiss:
UIViewController *controller = self.presentingViewController;
[controller dismissViewControllerAnimated:NO completion:nil];
Once the view controller is successfully dismissed i see the message in my console telling me that opengl error 0x0506 has appeared. This message is printed from methods swapBuffers of EAGLView and draw of CCSprite. Along with this message my whole scene becomes unresponsive. Tapping buttons gives no result.
I've tried a lot of things already. I tried pushing my view controller and adding it as a child instead of presenting but it doesn't even shows the view controller (viewWillAppear method doesn't get called), i also tried adding its view as a subview to my app's window but that also brings a lot of different errors.
I'm using cocos2d-x version cocos2d-2.1rc0-x-2.1.3.
Did someone solve such a problem before? Any suggestions?

before presentViewController, pause rendering:
CCDirector::sharedDirector()->pause();
CCDirector::sharedDirector()->stopAnimation();
call resume and startAnimation in completion block

Related

iPadOS13 (b7), UIMenuController and multiple windows

Having problems popping a UIMenuController when using multiple (side by side) windows.
So I handle a tap in a view then I set the firstResponder to that view, then I present a UIMenuController in that view and the canPerformAction: is called on that view - all good!
I then attempt the same in the adjacent window (same code obviously) and the canPerformAction: is still sent to the previous view (in the other window.) Indeed, pressing the menu also results in the handler being called on the other view.
Both views return YES from canBecomeFirstRepsonder:
Anyone got any ideas?
Thanks
Turns out you need to call [view.window makeKeyWindow] prior to calling [view becomeFirstResponder] prior to presenting the UIMenuController.
Makes sense I guess...

UIButton not getting focus

I have my code in Swift 3. I have two UITextFields and a UIButton in my view. I have the textFieldShouldEndEditing delegate of the first UITextField which is fired when I focus on the 2nd UITextField. However when I tap on the UIButton this delegate is not fired. I had thought that when a UIButton gets focus then the UITextField’s event will automatically fire since it is losing focus. However, when I tap on the UIButton, the cursor is still blinking in the UITextField, which means it is not losing focus.
Any ideas on why the UIButton is not getting focus will be most appreciated.
Thanks.
This is an infuriating aspect of developing forms on iOS. Button taps don't remove focus from UITextField / UITextView the same way they would in an HTML form.
I'm sure there are more elegant ways to solve this, but if I want to consistently do this across all forms I ensure that the following line of code is run when users tap on any buttons of mine.
- (void)userDidTapButton:(id)sender
{
[[[UITextField new] becomeFirstResponder] resignFirstResponder]
// the above embarrassing line of code basically creates a new textfield
// puts focus in it (thereby removing focus from any existing textfields
// and then removes focus again
// this ensures that delegate events fire on your existing textfields
// finally, run any other button code
}

Customize UIAlertController in iOS 8 to include standard elements like UITableView

I am used to customize UIAlertViews through the [alert setValue:someView forKey:#"accessoryView"] method. This creates customizable content for UIAlertViews with custom heights. However it only works on iOS7 and down. In iOS8 the UIAlertController have taken over, and I cannot customize it anymore, it will cut the height of the UIAlertView.
Is it impossible because of misuse of the UIAlertController, or how am I supposed to do it?
I am trying to incorporate a UITableView inside a UIAlertController with UIAlertControllerStyleAlert.
Thx.
I ran into the same issue right now. I looked at the private header for UIAlertController (https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UIAlertController.h) and found a promising property: contentViewController
And it turned out to be exactly the same as accessoryView used to be for UIAlertView, the difference being that you need to assign a UIViewController to this property rather than a UIView.
UIViewController *v = [[UIViewController alloc] init];
v.view.backgroundColor = [UIColor redColor];
[alertController setValue:v forKey:#"contentViewController"];
That piece of code will show a red view on the alert view! Happy UIAlertController customizing ;)
PS. It is a private property but using KVC there shouldn't be a problem App Store wise, I think.
Edit:
Some people complained that this isn't very safe. It's not a public API, so yes, Apple could change it in any release, causing this method to fail.
To make sure your entire app doesn't crash if that happens you could wrap the KVC call in a try block. If the property changes your controller won't show the content view, but it also won't crash:
#try {
[alertController setValue:v forKey:#"contentViewController"];
}
#catch(NSException *exception) {
NSLog(#"Failed setting content view controller: %#", exception);
}
Using this method in production can be risky, and I don't recommend it for important alerts.
I suggest not your wasting time trying to cram additional UI into a place where isn't supposed to be. Based on the last few years of improvements, Apple will probably add a custom view in the next iOS. Until then, have a look at a framework designed to handle this exact situation without subverting any best practices: SDCAlertView
It supports alerts that imitate the native alerts on iOS 7,8,9, including handling all of the nasty edge cases around sizing, button types, rotation, etc. It does support arbitrary custom views within the alert.
I use this library in Yahoo YMPromptKit for custom push notification prompts that look exactly like iOS native. Here's another example:
I think you can easily customize the UIView adding the controls needed and present it modally, unless you have any other specific reason to use only UIAlertController.
https://www.cocoacontrols.com/search?q=UIAlertview
You can do it with just a one of line of code using my UIAlertController category and replace existing alerts in application, check it here.

Implementing iAd in Cocos2d V3 with MyiAd

I downloaded iAd Banner Sample for cocos2d V3. Thanks so much for that code. The demo works fine and needs the user to tap Show Ad or Hide Ad button. Of course in my game I do not want the player to tap a button to Show Ads. In IntroScene.m I commented out the code that creates the buttons and added these lines at the end of init:
AppDelegate * app = (((AppDelegate*) [UIApplication sharedApplication].delegate));
[app ShowIAdBanner];
This is the same code that would have been executed if the Show Ad button had been pressed. I expected to see an ad without having to tap a button. However, I got no ad. I got the following error message in the log:
ADBannerView: Unhandled error (no delegate or delegate does not
implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain
Code=2 "The operation couldn’t be completed. Loading throttled"
There is -(void)bannerDidFail method in AppDelegate. It works by tapping button. How do I get the ads to show up automatically, without tapping a button first? Thanks.
The error seems to tell you exactly what is happening. Make sure that you have the following line:
bannerView.delegate = self; //bannerView is an object of type AdBannerView* that you created before
Check also that the class where the previous line is, implements the method:
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
I recently wrote a tutorial on integrating iAds in Cocos2d-x v3. Although the language is different (C++ instead of Objective-C), the procedure and syntax are rather similar: http://becomingindiedev.blogspot.com.es/2015/02/integrating-iad-in-cocos2d-x-v3x.html

Play sound when view controller loads

I'm trying to have the audio file play as soon as the view controller is loaded instead of manually hitting a button. Any suggestions?
The UIViewController has a method/function called viewDidLoad which executes when the UIViewController is loaded for the first time. If you want it to play each time it is shown, then you can use viewDidAppear
Documentation for this class is at: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html