I have two images for splash image in which one is simple image and second one is .gif file. If app open only first time, i want to show .gif file as splash screen. If app isn't open first time,i want to show normal images as splash screen.
how can do this by code.
You can use, AppDelegate's Life Cycle Methods, to determine when you want to show what.. Use these methods..
You can easily use a BOOL to determine whether your app is in running state of killed state, see below
- (void)applicationDidEnterBackground:(UIApplication *)application {
wasInBackground=YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
if(wasInBackground){
//Notify to show splash screen using simple image
wasInBackground=NO;
}
}
Hope this helps.
Cheers.
Related
I am working on a launch screen where I want to add a progress bar.
LaunchScreen.xib doesn't allows me to add a progress bar on the launch screen.
So is it possible to add a view controller as the launch screen for some time interval so I can add a progress bar on the launch screen of my project?
No,you can not. You can not add any logic code to it.
And also know that, at launch screen time. Your app is not launched at all. So your code about progress bar is not running.
I think the better way is using a launch screen first,then show a viewController with a progress bar as you like.
Treat launch screen as progress indicator and do loading stuff before return "Yes" in applicationDidFinishLaunchingWithOption.as return yes line executed then view controller load it's view. but don't try too much stuff before return yes like time consuming network operation.
Yes, you can. I wanted to have control how long the LaunchScreen is visible when launching the app which I did in the didFinishLaunchingWithOptions in the AppDelegate.m file.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
int time = 3;
sleep(time);
printf("[%i] %s ***** sleeping %i seconds *****\n",__LINE__,__FUNCTION__, time);
return YES;
}
I am trying to set time for the launchscreen.xib to make it last longer, for example 5 sec,since by default it disappears too quick i searched the web but found nothing useful, can it be done ?
Thanks
The apple documentation mentions this:
A launch file or image provides a simple placeholder image that iOS displays when your app starts up. The placeholder image gives users the impression that your app is fast and responsive because it appears instantly and is quickly replaced by the first screen of your app.
So essentially the launch screen cannot be made last longer because its only displayed when the app is starting up.
Still if you want you can
create a custom UIView with the launch image
make it the Initial View Controller by dropping the arrow in storyboard to your custom UIView
present your main View Controller on top of the launch image view after x seconds using dispatch_after
You can add this in your app delegate:
float delay =5.0;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[NSThread sleepForTimeInterval:delay];
}
If you use a viewController, you can present it again in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
making it the UIWindow's rootViewController, or presenting it modally from your application in the same method. This way, you can customize its dismissal. You can also add some animation to this viewController
So it may be another viewController than your launchScreen.
In order to make my app launch faster so I can start contacting with the server I made AppDelegate launch fast by cleaning all kind of work like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//[self redirectConsoleLogToDocumentFolder];
[[Ubertesters shared] initialize];
return YES;
}
What I want to achieve is loading my app faster to splash screen and show in the middle of the screen some kind of spinner (SVProgressHUD or UIActivityIndicatorView), so far I'm putting the spinner in the splash screen viewWillAppear.
This is what happens: didFinishLaunchingWithOptions load fast, then SplashScreen-viewDidLoad load fast and then viewWillAppear took a few seconds, but most of the way I see the image I set up as launch image and not my SplashScreen image with spinner animation.
Any ideas how can I make the launch image disappear faster and show my animation?
What exactly happens with an app when the user presses the home button? Does iOS make a snapshot of current app's state?
If I'm right, how to "slip in" another snapshot? I need it for showing the main iOS screen after user presses home button twice.
In order to achieve that, you could add a subview (i.e. ImageView with an image of your main screen) to your window in - (void)applicationDidEnterBackground:(UIApplication *)application.
When coming back (in - (void)applicationWillEnterForeground:(UIApplication *)application) you have to remove the subview.
However, Apple recommends to always show the latest state of the app (best user experience).
Example of AppDelegate implementation:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* other code */
self.overlayView = [[UIImageView alloc] initWithFrame:self.window.bounds];
self.overlayView.image = [UIImage imageNamed:#"mainscreen_screenshot.png"];
/* other code */
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.window addSubview:self.overlayView];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[self.overlayView removeFromSuperview];
}
iOS takes screenshot before your application goes to background.
I got it from Apple's official documentation.
Remove sensitive information from views before moving to the background: When an app transitions to the background, the system takes a snapshot of the app’s main window, which it then presents briefly when transitioning your app back to the foreground. Before returning from your applicationDidEnterBackground: method, you should hide or obscure passwords and other sensitive personal information that might be captured as part of the snapshot.
So, Here We can hide our "sensitive personal information" and the system takes a snapshot of the app’s main window and we are not able to change its feature.
# sensitive personal information
Set a blurry screen overlay before the app goes in the background and once the app becomes active remove this overlay (check #cweinberger's answer).
If it is iOS 7 or later you can use the function ignoreSnapshotOnNextApplicationLaunch
Also, allowScreenShot flag can be explored in Restrictions Payload.
For deeply read about it Then this is the best documentation.
My app uses a splash screen as per client requirement. I need to display this splash screen at every launch when user presses the home button again. Pressing app I need to load app from beginning or else display splash at a specific time interval.
Please help me to solve this.
You can disable the Multitasking capability of the app and make it start from scratch each time you re-open the app from the home screen.
#implementation MyAppDelegate
- (void) applicationDidEnterBackground:(UIApplication *)application {
exit(0);
}
#end
OR See "Opting Out of Background Execution" in the iOS Application Programming Guide:
"...you can explicitly opt out of the
background execution model by adding
the UIApplicationExitsOnSuspend key to
your application’s Info.plist file and
setting its value to YES."