cocos2d alternative in UiKit? - cocos2d-iphone

new in ios application development with uikit,can any one tell me what is alternative code of cocos2d replacScene In UiKit.used segue model but problem is i want use it programmatically like cocos2d.
thanks.

you can call the segue programatically by giving it an identifier and then using the following function
[self performSegueWithIdentifier:#"<segue identifier>" sender:<the sending view controller>];

Related

possible to instantiate WKInterfaceController in SwiftUI Watch project?

I have a project in which I have run into a limitation of SwiftUI on the Apple Watch. My proposed solution was to instantiate a WKInterfaceController to perform the needed functionality, and then return to using SwiftUI views. Is this possible? I tried to wrap my controller in a WKInterfaceObjectRepresentable object, but there doesn't seem to way to instantiate the interface controller from a Storyboard, as is possible on iOS according to this similar case:
How to add Storyboard ViewController into SwiftUI Project?
But Xcode tells me, "Cannot find UIStoryboard in scope"
Is there a way to create an InterfaceController from SwiftUI? Or perhaps I need to use a WKHostingController for my whole Watch project, so as to have access to the option of using InterfaceController objects?
Thanks.
You can navigate to an existing interface controller defined in a watchOS storyboard from SwiftUI by using NavigationLink with the destinationName:label: arguments, see here.
destinationName is the identifier used in the storyboard for that interface controller, eg:
NavigationLink(destinationName: "MyInterfaceControllerIdentifier") {
Text("Go")
}

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

cocos2dx OpenGL error 0x0506 when dismissing UIViewController

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

How do I put an href link in an IOS App (OpenGL)

My App is written in OpenGL and C++, I do not use XIB file for presentation. So how can I create an href link that the user clicks and takes them someone in the browser?
OpenGL only draws things to the screen. There's no concept of geometric objects. So you'll have to detect a click on the link text and call the appropriate iOS API invoking the URL.
Okay I think I found it:
NSURL *url = [NSURL URLWithString:#"http://www.iphonedevelopertips.com"];
[[UIApplication sharedApplication] openURL:url];