increase launch image time on xcode - iphone

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

Related

Iphone launch image disappear very fast

The launch image appear and disappear very fast in the iPhone.
How can I control this time? How much seconds is the default?
Thanks
You can use a sleep(time in seconds) function in the application:didFinishLaunchingWithOptions: to explicitly increase some time by yourself.
Eg :
sleep(3);
Will extend the time to 3 more seconds.
Note : As rmaddy said, make user stare at splash screen for a long time is not a good practice. But you can use this in customer's demand.
Happy coding. :)
There's no default — it stays up until your program has been loaded and returned from application:didFinishLaunchingWithOptions:.
If you want to keep the image up under programmatic control then you'll need to place it on screen manually as the first thing the program displays, then dismiss it through the usual channels. This would be relatively easy on a pre-5 iPhone (just put up a big UIImageView with Default.png in it) but as of the iPhone 5 and with the iPad you're going to have to make some sort of decisions about which default screen to show.
You can also try to add a sleep time in your didFinishLaunchingWithOptions method as below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[NSThread sleepForTimeInterval:3.0f]; //add 3 seconds longer.
//other code....
}

Iphone application gets stuck after unlocking screen

When i keep my application open for awhile, the iPhone/iPod locks the screen. When i unlock it my application gets stuck for like 2 seconds and then it resumes and keep functioning as usual. Why is this ? and how can i prevent it ?
To prevent this from hapenning is there any PLIST method where we could stop the process of the application when it goes to a locked screen (Might not be a better idea)
In your application delegate do you have any code that could slow down your app? Check the following methods?
-(void) applicationWillResignActive:(UIApplication *)application
-(void) applicationDidBecomeActive:(UIApplication *)application
-(void) applicationDidEnterBackground:(UIApplication*)application
-(void) applicationWillEnterForeground:(UIApplication*)application
-(void) applicationWillTerminate:(UIApplication *)application
Also use the above methods ensure you application suspends properly.
Log when your app receives a memory warning inside:
-(void) applicationDidReceiveMemoryWarning:(UIApplication *)application
Maybe when you suspend or reopen your app some there is a memory issue.
I'm not quite sure about the answer for your first question (you maybe do some heavy things inside the applicationDidBecomeActive method or the app simply reallocates memory), but i can answer the second one.
You can simply prevent the auto lock by calling:
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
A good palce for this is inside the applicationDidFinishLaunching method of the app delegate.

Simulate memory warnings from the code, possible? [duplicate]

This question already has answers here:
iOS Development: How can I induce low memory warnings on device?
(10 answers)
Closed 9 years ago.
I know i can simulate a memory warning on the simulator by selecting 'Simulate Memory Warning' from the drop down menu of the iPhone Simulator. I can even make a hot key for that.
But this is not what I'd like to achieve. I'd like to do that from the code by simply, lets say doing it every 5 seconds. Is that possible?
It is pretty easy actually, however it relies on an undocumented api call, so dont ship your app with it (even if it is in a inaccessible code path). All you have to do is use [[UIApplication sharedApplication] _performMemoryWarning];.
This method will have the app's UIApplication object post the UIApplicationDidReceiveMemoryWarningNotification and call the applicationDidReceiveMemoryWarning: method on the App Delegate and all UIViewControllers.
-(IBAction) performFakeMemoryWarning {
#ifdef DEBUG_BUILD
SEL memoryWarningSel = #selector(_performMemoryWarning);
if ([[UIApplication sharedApplication] respondsToSelector:memoryWarningSel]) {
[[UIApplication sharedApplication] performSelector:memoryWarningSel];
}else {
NSLog(#"Whoops UIApplication no loger responds to -_performMemoryWarning");
}
#else
NSLog(#"Warning: performFakeMemoryWarning called on a non debug build");
#endif
}
I wrote an apple script that will hammer the simulator with memory errors, it is a bit extreme but if your code survives, then you can be more confident...
on run
repeat 100 times
tell application "System Events"
tell process "iOS Simulator"
tell menu bar 1
tell menu bar item "Hardware"
tell menu "Hardware"
click menu item "Simulate Memory Warning"
end tell
end tell
end tell
end tell
end tell
delay 0.5
end repeat
end run
Post a UIApplicationDidReceiveMemoryWarningNotification notification to the default notification center:
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification object:nil]
Just alloc-init big objects in a loop, and never release them. That should trigger a memory warning pretty quickly, I'd imagine.

How to delay Default.png?

How can I delay the app loading to show the splash screen for longer?
You should let the app start as usual then make the first view that appears have the identical image on it as the splash screen. Start a timer and then replace that view with your real application root view after a few seconds.
Deliberately delaying the actual application launch is a big no-no.
UPDATE: No seriously, DON'T do this!
Or us the C function
sleep(9);
Putting this in applicationDidFinishLaunching: will cause you program to pause for 9 seconds, any other integer may be entered as well.
EDIT: I've learned a lot in the past year. Don't do this. The reason being that the springboard will automatically stop the app launching if it takes too long. That timing is poorly documented so even one second can result in the app failing.
This question is similar: splash screen like tap tap revenge 3
Basically, in your applicationDidFinishLaunching:, add an image view on top of other views containing your Default.png.
See the above discussion of why you probably should not delay your app load in this way. But if you happen to have a scenario where sleeping for short duration would be preferable to the overhead of switching out a view, use NSThread's sleepForTimeIntervale instead of sleep(). It's more framework friendly and you have more granular control over the sleep time:
[NSThread sleepForTimeInterval:0.75]
I had a situation where the client had to demo the launch image. So, this was my solution..
- (void)applicationDidBecomeActive:(UIApplication *)application
{
UIImageView *defaultImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default#2x.png"]];
[self.window addSubview:defaultImageView];
sleep(2);
[defaultImageView removeFromSuperview];
[defaultImageView release];
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
You can use it sleep method to get this result "
sleepForTimeInterval
", If you want to get it launch time, do like :
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
[NSThread sleepForTimeInterval:8.0];
}
It will delay the launch by 8 seconds
Warning : But it is not recommended by apple, as it will the watchdod about long time for your app loading, It can kill your app.
But incase if you need it to get some specific screenshot or for some in-house use, you can use to solve for purpose but never in app submission.

Awake from sleep event on the iPhone?

Is there any way to detect if the iPhone wakes up from sleep while you're app is running? Eg: your app is running, the user locks the screen (or the screen auto locks) and some time later the user unlocks the screen and up pops your app. Is there some way to get an event at that point or detect it somehow?
I've tried searching the Google and this forum, but I can't seem to find anything about it.
See applicationDidBecomeActive: on UIApplicationDelegate.
Stick these in you AppDelegate.m file:
-(void) applicationWillResignActive:(UIApplication *)application {
NSLog(#"Asleep");
}
-(void) applicationDidBecomeActive:(UIApplication *)application {
NSLog(#"Awake");
}
#Kevin - Nothing wrong with your answer - thanks by the way. Just thought I'd save the next person a Google search.