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."
Related
I am trying to smoothly close down my app.
First I put the app in the background and tried to use exit(0) to close down the app:
//home button press programmatically
UIApplication *app = [UIApplication sharedApplication];
[app performSelector:#selector(suspend)];
//wait 2 seconds while app is going background
[NSThread sleepForTimeInterval:2.0];
//exit app when app is in background
exit(0);
My problem is, when I check to see what apps are running in the background, the app is still there. I thought exit(0) would remove it from the background.
It appears my app is going under recently used. Is there a way to programmatically remove it from that list?
You can't programmatically remove an app from the "recently used apps" list. When a user double-taps the Home button, the list of recently used apps is just that - a list of recently used app. It has absolutely nothing at all to with whether the app is fully terminated or suspended in the background.
Calling exit(0); simply terminates your app. But it was still recently used so it appears in the list when the user double-taps the Home button.
In XCode edit the info.plist adding the setting "Application does not run in background" with a value of YES to make your application exit every time:
Setting this will add UIApplicationExitsOnSuspend to info.plist:
<key>UIApplicationExitsOnSuspend</key>
<true/>
I had used [NSThread sleepForTimeInterval:5] in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions of AppDelegate.m. To increase the 'Splash screen display time' sleepForTimeInterval method were used. Will this line usage cause App to be reject by Apple Verification ? I gone through following link for "App Rejections"
https://developer.apple.com/app-store/review/rejections/
https://developer.apple.com/app-store/review/guidelines/
Can anyone help to make sure this method never affect App Publish ? Advance thanks for any help.
Don't do it! If you want a splash screen to display for some period of time, create a view controller whose view looks exactly like your splash screen. Display that view controller at launch and leave it there as long as you like. Putting the main thread to sleep is a recipe for disaster.
That said, why are you planning to torture your users?
Your app may not get rejected, but it definitely will be a bad user experience.
The purpose of the splash screen give the impression to the user that the app is responsive. The splash screen is shown as soon as the user taps the icon, to give the feedback that the app is loading. This time should only be used to load the essential components required to start your app.
iOS does have some limits on how much time is allowed for your app to load. If it does not respond in time, the OS will kill the app.
Why would you want to add another 5 seconds to the launch time?
In the documentation (App States and Multitasking) which Apple provides:
If your app is launched into the background instead—usually to handle some type of background event—the launch cycle changes slightly to the one shown in Figure 3-3. The main difference is that instead of your app being made active, it enters the background state to handle the event and then is suspended shortly afterward. When launching into the background, the system still loads your app’s user interface files but it does not display the app’s window.
How to simulate to launch an app into the background in iOS Simulator?
If an app launched into the background, will the UIApplicationDelegate method -applicationDidEnterBackground: be called?
No, applicationDidEnterBackground: won't be called in this case.
You can't simulate real launch into background behaviour if Xcode is attached.
(But you can simulate launch with UIApplicationLaunchOptionsLocationKey key using location simulation)
I tested significant location change API on real device and collected logs after tests. Results:
application:willFinishLaunchingWithOptions: is called with UIApplicationLaunchOptionsLocationKey key.
But applicationDidEnterBackground: is not called.
You just have to launch your app and then go to home screen in simulator - press cmd + shift + H and the app is in background state and - (void)applicationDidEnterBackground:(UIApplication *)application in appDelegate is called .
My app checks the GPS while my app is not the active app and I use AVAudioplayer too in background.
It works fine and stays in the background doing its thing, but ios7 displays this red top banner with my app name flashing on it when it is not the active app.
How can I disable this banner, it is annoying to use other apps that are squished down 1 line?
I know this can be done as I have other GPS based background apps that don't display this flashing banner.
EDIT - So we found the answer quickly but the solution evades me:
If I stop OpenEars pocketsphinxController from listening with a button that calls this method while the program is active, the banner disappears when the app loses focus:
-(void) mystopListening{
NSLog(#"Tried to stop listening");
[pocketsphinxController stopListening];
}
BUT if I call the same method from my app delegate with (I had to import my view controller.h file in my app delegate.h and add -(void) nystopListening; in my view controller.h to make the below execute properly):
- (void)applicationWillResignActive:(UIApplication *)application{
myViewController * vc = [[myViewController alloc]init];
[vc mystopListening];
}
The banner persists! It is a little like ios7 has decided I am a recording culprit before I even have a chance to turn it off. OR, am I even turning it off?
How do I do this effectively and in what event?
EDIT - So it turns out I am not really turning pocketsphinxController off when 'mystopListening' is called from the app delegate. I know this because it DOES log the 'Tried to stop listening' when called from app delegate but the pocketsphinxController does not respond with its 'pocketsphinxDidStopListening' method. PocketsphinxController does call its 'pocketsphinxDidStopListening' method when I call 'mystopListening' from a button while the app is active.
Why won't the pocketsphinxController respond when called from from the app delegate, I must be doing it wrong?
Thanks,Carmen
Turns out I was not really calling the original pockectsphinxcontroller instance from my app delegate.
As a workaround to the problem I did this:
My app always has a timer running, so in my app delegate where I get notice of when app goes to inactive and comes back active, I just set global flags so my timer can know app active status. Then my timer just uses pockecsphinxcontroller methods to stop and start listening and voila, the banner is no more while app not active.
I'm programming a quiz for the iPad and when the user presses the homebutton while in a quiz and relaunches the app I want the quiz to be already cancled and back on the Startpage of the app.
Now it simply gets back to the last view it was on.
Also I want it to show the splashscreen again when the app relaunches.
A complete reset of the app, when pressing the homebutton, would be great.
Thanks in advance
Choose the 'application does not run in background' option in your project's plist. If the option isn't there, press the '+' on the side to add the property.
This will ensure that the app starts afresh every time it's opened.
So, you want to disable multitasking?
Set UIApplicationExitsOnSuspend = YES in your info.plist.
Unless you just want them to resume through the screen, in which case you'll want to look into the lifecycle callbacks for your AppDelegate.