Cocos2d crash when using dictation (microphone button) with CCTextField - cocos2d-iphone

I get a permanent crash when tapping on microphone button during the input in CCTextField. There's no crash on iPhone 4s iOS8, but the game is crashed on iPhone 5s iOS9 and iPhone 6+ iOS9. This issue seems to be the same as described here http://discuss.cocos2d-x.org/t/engine-crash-on-ios7/9129/10 and there's a solution for cocos2d-x there. Can someone provide a solution for cocos2d-objc ?

Okay, here's the workaround for cocos2d-objc:
- (void) update:(CCTime)delta{
CCGLView *ccglView = (CCGLView *)[[CCDirector sharedDirector] view];
[EAGLContext setCurrentContext:ccglView.context];
}

Related

ios 10 - UITabBarController UITabBarItem - items slow to render

Upon login the initial display of my UI worked fine in iOS 9 with the UITabBarController showing all icons appropriately but in iOS 10 there is a noticeable delay of up to 5 - 10 seconds without any error in the log.
I've posted a bug to Apple ID- 29127274
The fix is below...
-J
Here is the code that cause the problem:
#implementation MyTabBarController
//...
- (void)viewDidLoad
{
[super viewDidLoad];
//the code below was causing the delay ... this worked find in iOS9
//tried legacy #define style
//[self setSelectedIndex:int(SelectedLandingToTab)];
//tried extern style .... both fail
//[self setSelectedIndex:SELECTEDLANDINGTAB];
}
//...
#end
If you comment out the setSelectedIndex then the UITabBar shows properly without delay.
-J

Touch Up Inside event not working after rotation of tab bar

I have a button in one of view controller of tab bar controller. All set up in storyboard. I registered action method like this
- (IBAction)buttonPressed:(id)sender {
NSLog(#"Button pressed");
}
The thing is that once I make left and top constraints (to force it stay in the right upper corner) touch up inside event stops working after I change rotation. So just open app in portrait mode - method is working. Change to landscape and I cannot tap button suddenly.
I've recreated problem in this easy example project.
Many thanks.
Just put the following code in you TabBarViewController class.
- (void)viewDidLayoutSubviews
{
// fix for iOS7 bug in UITabBarController
self.selectedViewController.view.superview.frame = self.view.bounds;
}
Recently I noticed same bug in my application. First I tried Slavco Petkovski method. But this caused me another bug with rotating and getting right bounds and frame, so I kept searching.
I found another solution for this problem, mainly setting autoresizing mask of view controller's view in xib. But since arrows in inspector in my Xcode (version 5.0.1) are inactive and you can't set them, you have to open xib file in text editor find autoresizingMask property for main view and change it like this:
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
EDIT:
Alternatively you can do this in your view controller's code - same result as in changes in xcode:
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

iOS 6 Game Center Crash on Authentication

I am building a game in Cocos2d-iPhone, and while I was updating to iOS 6, I noticed that Apple changed the way Game Center authentication is done, using authenticateHandler instead of authenticateWithCompletionHandler.
I added the new authentication method, but the game now crashes if a player is not already logged in to Game Center. There is no problem authenticating if a user is already logged in.
Here is my code:
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"6.0"))
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
if (viewController != nil)
{
AppController *appDelegate = (AppController*)[UIApplication sharedApplication].delegate;
[delegate.viewController presentViewController:viewController animated:YES completion:nil];
}
else if (localPlayer.isAuthenticated)
{
NSLog(#"Player authenticated");
}
else
{
NSLog(#"Player authentication failed");
}
};
}
It seems like it's crashing when trying to present the Game Center viewController, even though I use the exact same code to present the GKTurnBasedMatchmakerViewController with no issues.
Any help would be much appreciated.
EDIT:
Here is the exception getting thrown on crash:
Uncaught Exception UIApplicationInvalidInterfaceOrientation: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
Here you can find useful information about your crash, I think it is the underlying reason.
https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html
Apps should provide the delegate method application:supportedIntefaceOrientationsForWindow and ensure that portrait is one of the returned mask values.
I added below code to fix this crash.
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Had similar issue, I was testing the isAuthenticated and authenticateHandler from within viewDidLoad, kept crashing when trying to present the Game Center View whilst in the middle loading the current view. I moved this test into viewDidAppear
(void)viewDidAppear:(BOOL)animated{
it works fine now...
Also for ios 6, Game Center will only prompt a non authenticated user once, if they decline to sign-in, it will disable Game Center for that app, the user will then have go into Game Center to log in.

How do you detect what UIPickerView row has been selected using an if statement

I have made a button so that when it's pressed by the user and a particular row(s) are selected it does something.
So far I have this:
if (pickerView selectedRowInComponent:0) {
[mailComposerTwo setToRecipients:[NSArray arrayWithObjects:#"email#blah.com",nil]];
}
It works on its own. But when I do the if statement multiple times it crashes.
An ways of making it work?
Any help appreciated, thanx.
The problem probably lies with your mail composer, not the picker view. When you show the composer, make sure that you only create it if it hasn't already created.
Also, make sure you release it after you show it:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
...[configure the picker]
[rootContainer presentModalViewController:picker animated:YES];
[picker release];
NSArray *finalList = [[NSArray alloc]init];
//put all your if statements
if (pickerView selectedRowInComponent:0)
{
[finalList arrayByAddingObjectsFromArray:#[#"email#address.com",#"second#address.com",...];
}
if (pickerView selectedRowInComponent:1)
{
[finalList arrayByAddingObjectsFromArray:#[#"another#address.com",#"fourth#address.com",...];
}
//end of if statements
[mailComposerTwo setToRecipients:finalList];
[self presentViewController:yourInitializedMessageController animated:YES completion:^{NSLog(#"message controller is presented");}];
This will do a single method call rather than continually reassigning which for some odd reason is causing your exception. presentModalViewController:animated: has been deprecated as of iOS 6.0? if not 7.0 I believe.
NOTE! Make the message controller a property of the main view controller. It is good practice so that it is not auto-released by iOS if you need to bring it back up. However if you use MFMessageComposer iOS will keep messenger allocated or running in a thread somewhere so initializing a view controller for it is quick.

CCLabelBMFont Label takes long time to load!

I have a game. In game there is a help text. The game menus are transitioned on sliding in and out manner. Like if you click "Help" button on "Main Menu", Main menu slides out and help menu slides in.
Now i got problem while loading "Help Menu". The help menu consists of a scroll view and help texts are loaded in scrollview when it is initialized. The Text in Help Menu are CCLabelBMFont Label. The help text has multiples lines (upto 146) lines. My problem is when I click on Help menu, the sliding In takes up to 10 secs to come up. I know it's due to the long help text that is created using CCLabelBMFont.
Is there any solution of this case. When I decrease the lines of help text to 50, it works fine. I directly created the label with following code in HelpMenuLayer.m
CCLabelBMFont *contentLabel = [[CCLabelBMFont alloc] initWithString:#"Objective:"
"\n........."
.
.
.
fntFile:"fontFile.fnt"];
contentLabel.position = ccp(0.0f, 0.0f);
[scrollview addChild:contentLabel]
[contentLabel release];
Any comments or suggestions are greatly appreciated. Thanks in advance. I really need help :(
I solved the above issue using png image. And wrote down in some steps in following blog of mine. Please visit following link.
http://learninprogram.blogspot.com/2011/06/solution-to-cclabelbmfont-bitmap-fonts.html
Thanks for everyone who tried to help me and helped me actually. Happy sharing!!
Well it is probably UIKit causing any slowness. Cocos2D and UIKit do not play well together in my experience.
Anyway I don't know for sure what is wrong. Here is my usage of CCLabelBMFont (which does not use UIKit but it should be the same):
CCLabelBMFont *multiplierLabel = [CCLabelBMFont labelWithString:[NSString stringWithFormat:#"%i", [player scoreMultiplier]] fntFile:#"projectOneTitle1.fnt"];
multiplierLabel.position = ccp(winSize.width*0.9, winSize.height*0.95);
multiplierLabel.tag = 9845;
[self addChild:multiplierLabel];
That probably won't help, but in the off chance that it does I am posting it. Good luck.