We do not want to use exit(0) to make the app close, we do however want to allow the app to go to background programmatically and process away, per users allowing this action. Is there a way to send the app to the background programmatically without exit? Simulating the click of the home button?
Thank in advance!
Is there a way to send the app to the background programmatically without exit?
No. The user is supposed to be in control of the app -- the app shouldn't move to the background (or exit) of its own accord.
Not possible. Home button clicks run into the private GSEvents framework. It's exit() or none unfortunately.
The below code can be used to send iOS app to background programatically without exit
DispatchQueue.main.async {
UIApplication.shared.performSelector(inBackground:NSSelectorFromString("suspend"), with: nil)
}
Related
We have a multiplayer game and sometimes user quit the game so we would like to know how did user quit the game. Can we use didEnterBackground for that?
We would like to know whether user quit the game by clicking exit button, or by incoming call, or by home button to exit.
When you press home button your application is sent to background and applicationDidEnterBackground will get call first and if it is by call, sms then applicationWillResignActive will get call first.
This is not perfect answer of your question but this might help you in some.
in the appDelegate.m File u have this function:
- (void)applicationDidEnterBackground:(UIApplication *)application
write the code you want in it. (saving data or anything)
First of all, the user interface guidelines forbid quitting an app programmatically and based on what I have read, apps the provide an exit button will be rejected.
If by 'quit the game' you mean something along the lines of 'terminated gameplay', then that should not be a problem.
Also note that pressing the home button does not exit the app. It simply sends it to the background. There does not appear to be any facility to detect why the app left the foreground, which probably means that Apple wants your app to handle all such cases in the same way: by saving state and being prepared to restart where execution left off. Note that an application in the background can be terminated at any time, hence the need to save state.
The answer to your question therefore would seem to be: don't do that.
In my window based iPhone application i have developed a rating alert using iRate to rate my application. it displays an alert view.
this alert was displayed when app launches.
But i need to display this alert just before the app going to close when a user has selected to press the home button to exit the app.
it displays only 0.5 secs so it is invisible so what to do .. i tried it in applicationDidEnterBackground & in applicationWillResignActive and in pplicationWillTerminate but no use
what to do thanks in advance...
You can't do this. When your app gets the applicationWillTerminate or applicationWillResignActive messages, your app has a limited amount of time to do cleaning up processes before the OS kills it. Displaying a message will delay the exiting of the app and so it isn't allowed - it will just display very quickly and then the app will be killed because it hasn't finished.
If a user has selected to press the home button to exit the app, they want to exit the app straight away. They don't want to exit the app some time after they've pressed it just because you want to show them some other things.
applicationDidEnterBackground: is the method you can use to know when you're app will be backgrounded. You only have 5 seconds to return from this method though so it may not be the best place to show an alert view
If you love your users, don't show rating alerts. Create a great app to get great ratings.
Hey guys. I have a navigation-based app, and I want to control what the app does when it enters the background. In this app, the user has usually made it to the 3rd or 4th view controller before hitting the home button.
As of now, pushing the home button forces the user to restart the app from the beginning every time. This is a pain because it takes near a minute for the user to get back to where he was.
Is there a way to "close" the app while keeping track of the user's last page? I know that applicationDidEnterBackground: only allows a few seconds to close-out the session, and I dont know of any other way to accomplish this.
If anyone has any ideas, please let me know. Thanks!
If your app is running on a 4.0+ device then the default behaviour will be to return to where the app was before it entered the background. If it is on an older iOS then you will have save any session information yourself.
I face a very weird experience, when i receive multiple notification and then didn't response to it immediately. After a while, i pressed the view button and it open my application and show black screen.
BTW, the application is running at background when i click the view button and it also doesn't trigger didReceiveLocalNotification.
Does anyone know what is the problem?
Thanks
When your application is running in background and if notification come, then it will call applicationFinishLauchingwithOptions Method. So write your logic in that part.
HI
can we open our app without tapping it again on its home icon.
I am making a call in a addressbook app and when call is made than it call the phone app than is it possible after calling we can call our app again without tapping on it after the call is ended.
Sample code will be more helpful.
thanks
Short answer - no, once you leave your app, user has to return there.
I'm not 100% sure what you are asking, but if this is what you are shooting for:
a) Your app is running, and it causes a phone number to be dialed.
b) After the call is complete, your app is automatically re-launched.
Then no, this is not possible.