cocos2d how to make loading image last longer? - iphone

i want to make my game loading image last longer(Default.png), how?

What you can do is, in your application did finish launching method you can use NSThread to sleep for time interval of 2 sec.
Like this
-(void)applicationDidFinishLaunching
{
[NSThread sleepForTimeInterval:2.0f];
}
But if you want to do some work behind the sense than you can dispatch a custom queue to get the work done using Grand Central Dispatch.
Check the apple documentation on it.

In the Appdelegate :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
sleep (3);
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
The sleep (3); means that the loading screen (Default.png) will load/sleep for 3 seconds.
So actually you just have to put the seconds you want in the ().
For example 5 sec : sleep(5);

Related

how to display specific screen for first ever time the app has been launched [duplicate]

This question already has answers here:
How to detect first time app launch on an iPhone
(17 answers)
Closed 8 years ago.
I'm trying to find a way in which i can detect the first ever time my app has been launched/used so i can display a set-up screen. After the first ever launch has happened and the set-up has been completed i would like the app to just default to my main screen.
Does anyone have any ways in which i could achieve this? Also, i would like the app to default to the main screen even if the app has been killed after the set-up has been completed once.
I'm new to iOS and was thinking of possibly using a plist to store a value which would be changed on the first ever launch? But i'm not sure, any help and advice would be much appreciated with any bit's of code that anyone would like to share.
Thanks
Try this way..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
if ([[NSUserDefaults standardUserDefaults] ValueForKey:#"FirstLaunched"] isEqualtostring:#"YES"]) // Not first Launch
{
self.window.rootViewController = Main Screen;
}
else //first Launch
{
self.window.rootViewController = ONE TIME SCREEN;
[[NSUserDefaults standardUserDefaults]setValue:#"YES" forKey:#"FirstLaunched"];
}
[self.window makeKeyAndVisible];
return YES;
}

iPhone :: Objective-C - AddSubview in my initial UIViewController ViewDidAppear

Hihi all,
This could very well be a silly question. I would like to navigate to my "Login View" upon the launching of my application. My current tries:
In my first UIViewController's viewDidAppear method, perform a [self presentModalViewController:LoginView animated:YES], this works, but the screen shows my main UIView first, then slide my LoginView from bottom to top. I can't find a way to perform it without the animation.
In my first UIViewController's viewDidAppear method, perform a [self.view addSubview:LoginView.view], it ends up with exc_bad_access error.
Basically, my requirement is to perform certain checks upon starting of the application, if a login is required, the application shall display the LoginView, otherwise, it should stay as my main UIView.
Please advice what is the best way of achieving this, instead of the above two silly methods. Thanks in advance!
:)
How about trying it in **- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {**
example :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
LoginViewController *aLoginViewController = [[LoginViewController alloc] init];
[self.navigationController presentModalViewController:aLoginViewController animated:NO];
[aLoginViewController release];
return YES;
}
your 1st step is a good way..
but to stop animation, its very simple. Set animated to NO.
[self presentModalViewController:aLoginViewController animated:NO];
once ur done with ur validation, just dismiss this aLoginViewController.
Instead of -viewDidAppear, it sounds like you want to use -viewWillAppear:, which will allow you to present your login controller before the initial view is displayed.
-presentModalViewController:animated is the right method to display your login controller's view.

increase launch image time on xcode

for iOS devices, after set a custom launch time image, when tested on simulator it remains about 4s but when tested on iphone it is hide after less than 1s! Assumed that depends on processor but how to modify that visualization time?? Thanks.
Better option would be to put a sleep of 5 seconds in your appDidFinishLaunching: method.
Statement at the start of your appDidFinishLaunching: method.
sleep(5);
Hope this helps you.
Note:- You may want to increase the time from 5 seconds to whatever time that is suitable for you. Thanks
EDIT: You may need to include #import <unistd.h> statement.
We can also increase the duration time of App Launch Image by implement applicationShouldLaunch as below,
#import "MSTRMobileAppDelegate.h
#implementation MSTRMobileAppDelegate (Extension)
- (BOOL)applicationShouldLaunch:(UIApplication *)application errorDescription:(NSString**)errorString
{
sleep(10);
return TRUE;
}
#end`
You can't actually change of the loading time itself - that's decided by the operating system and how it takes to load.
BUT - you can make it feel like it takes longer by simply putting a UIImageView with your image on top of your main window application and removing it using an NSTimer - you can even use nicer animations to make it disappear like make it fade out.
Add the sleep function to your this method below in your delegate class.
NOTE: the name of the method is NOT the same as suggested in the answers above.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(3); //PUT THE SLEEP HERE AND IT WILL HOLD YOUR LAUNCH IMAGE FOR HOWEVER SECONDS YOU "SLEEP"
// Override point for customization after application launch.
return YES;
}
This worked for me. This post is intended for future seekers to this problem not that I'm trying to answer a question that was asked 2 years ago

iOS 4.2 Default.png loads then 1 sec of solid gray then my UIWebView appears

How do I make my app seamless from the default.png to my App? Should I load it somewhere else? FYI I only have an iPod Touch 2nd Gen for testing running 4.2.1(8C148) The 4.2 simulator does the same thing. 4.3 simulator works fine.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:YES]]];
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
What is happening it is taking a few seconds before UIWebView fully loads its content. So whilst it is loading, you are seeing the background color of the web view. If you don't want the blank screen, I would advise showing an activity indicator, to show that something is happening.
Alternatively, set the webViews delegate as your self and only perform [self.window makeKeyAndVisible] in the webView' delegate message named `webView:didFinishLoad‘
The latter method is unadvisedly though, as your effectively delaying the start of your app for several seconds.
In viewDidLoad,
webView.delegate = self;
Now in a separate method, called -(void)webViewdidFinishLoad:(UIWebView *)theWebView
[imageView removeFromSuperview]
[imageView release]

How to reliably avoid iphone idle?

I don't want my app to go to sleep (shut screen off) unless the user puts it out of its misery. I'm trying what I think is simple code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
application.idleTimerDisabled = YES;
This works most of the time, but the app still occasionally goes to sleep. I'm not sure of the pattern. Is there anything that can reenable the idle timer?
Some classes (such as MPMoviePlayerController) will enable/disable the idleTimer as part of their normal workings.
rpetrich is right.
I was launching a MoviePlayerController out of my app and on the callback I was forced to set idleTimerDisabled to YES again... But there's a remark here because for some reason iphone is discarding this set...
I solved it, this way:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
application.idleTimerDisabled = NO;
application.idleTimerDisabled = YES;
}