Killing an iOS app programmatically - ios

I have an app when a specific action fires I close the app and ask the user to reopen it again.
The problem is when the app executes exit(0) the app stays in the apps stack (when I click the home button twice). I want it to be killed completely so that viewDidLoad() will be executed again when the app opens.

You cannot terminate an app on it's own.
From Apple's Human User Guidelines...
Don’t Quit Programmatically
Never quit an iOS application programmatically because people tend to
interpret this as a crash. However, if external circumstances prevent
your application from functioning as intended, you need to tell your
users about the situation and explain what they can do about it.
Depending on how severe the application malfunction is, you have two
choices.
Display an attractive screen that describes the problem and suggests a
correction. A screen provides feedback that reassures users that
there’s nothing wrong with your application. It puts users in control,
letting them decide whether they want to take corrective action and
continue using your application or press the Home button and open a
different application
If only some of your application's features are not working, display
either a screen or an alert when people activate the feature. Display
the alert only when people try to access the feature that isn’t
functioning.
Have a look at this answer: https://stackoverflow.com/a/8491688/742298

Related

iOS: Touch ID prevent user from closing app when pressing too strong

is it possible to prevent the app from closing when my app asks for a fingerprint and the user presses the home button instead of only let the finger rest? I know and understand that it shouldn't be possible everywhere else, but it would be nice if the app wouldn't close when asking for the fingerprint.
It is not ever possible to change regular system behaviour, even though some users might press too hard and go back home that is the behaviour that everyone expects, want to go home, press the home button and it always works
This is not possible, what you are trying to do is getting out of the scope of your application and change the behavior of the device. Apple won't allow it, ever.
They might change the behavior if they think it's better to handle it like that, you can send them a message. But they'll probably never do that as they are killing Touch ID for the sake of Face ID.

Start app and navigate to the view previously displayed

I have an app (iOS, Swift) which is usually started in the morning by the user. The user will press a couple of buttons, enter some text, move to other views (using a navigation controller) and so on. When everything is filled out the right way, the user will put the iPhone into standby mode. As far as the app life cycle is concerned, it will enter the background state. When the user opens the app again, he will still be on the same page, with the same parameter, ... Everything is fine.
In case of a suspended app (due to a lack of resources or other stuff), the app will start again from the beginning and not from the view where the user has navigated to before. In such a case, what's the best way to navigate to the specific view the user was when bringing the phone into the standby mode and keep respectively build up the whole navigation stack as it was before the suspension?
You can use Apple state restoration and preservation technique for this purpose. Here you can find an example provided by Apple.
Hope this will help.

Objective C - Detect if finger is held on screen at app startup

I'd like to perform an action when the user has their finger held on the screen when my app startups.
To give an example: When the App launches and the launch screen is showing up, the user has a finger on the screen as long as the first ViewController appears. When the first ViewController gets into the viewDidAppear() function, I want to detect, that the users finger is on the screen and perform an action, like f.ex. jumping straight into the lastest received email. Basically this is supposed to be a kind of shortcut to an main action.
Is there any method to detect an already laying finger on the screen? To be exactly I'd like to check for the tap in viewDidAppear()
Unless the nature of Time has changed since the last time I checked, your app cannot detect what the user was doing before the app launched. The app, ex hypothesi, was not running at that time. And the mere presence of a finger on the screen during app launch will not generate a touch event that the app can detect.
The system can detect it, however, since is running before your app launches. That is why Apple added force-touch Shortcuts (for appropriate hardware). The only way you can do what you're asking is to rely on that API. Hardware that lacks this feature will simply have to do without this feature.
(After all, this is how Apple makes money: by trying to make users jealous of hardware they don't have, so that they buy new hardware. You would want to rob Apple of its income by reading this feature backwards onto old hardware, even if you could, now would you?)

iOS app printing while running in the background

I have an iOS app that automatically prints a receipt to a thermal receipt printer when an order comes in and works great. However, if the app is in the background, it does not print. Is it possible to allow it to print while running in the background?
There are only a few occasions you are allowed to run certain tasks in the background. See the Apple documentation: https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20
For example: playing audio, fetching the user location, sending notification or certain data from network in the background is allowed. Running your own logic during a background service is, as far as I understood, not allowed (like running it one hour after your app is gone to sleep/background mode).
The only thing that is perhaps an option, is to utilize the time your app has to finish an task after the home button is pressed. There is a timelimit however of 10 or 15 minutes.
I don't know if this is suitable for your situation?
See this stackoverflow question: iOS application executing tasks in background
And this particular piece of code to run the task in the background: https://stackoverflow.com/a/11809211/2740112
Another option is to use Guided Access, which is introduced since iOS6.
With it, you can prevent exiting the app. It's only usefull when using only the app on the device that needs to be used.
Information below from http://www.assistiveware.com/support/faq/page/136:
To turn on Guided Access, do the following:
Go to the Settings app on your device's home screen.
Tap General.
Tap Accessibility.
Under the Learning section (scroll down if necessary), tap Guided Access.
Toggle Guided Access to ON.
Tap Set Passcode and enter a four digit passcode. You will be prompted to enter it again.
(Optional) Toggle Enable Screen Sleep to ON if you want to be able to put your device to sleep with the Power button, otherwise the Power button will be disabled.
To start Guided Access for an app and prevent it from being exited, do the following:
Open the app that you want to lock in.
Quickly press your device's Home button three times to bring up the Guided Access menu.
Tap the Start button in the top right corner of the screen to activate Guided Access. A message stating "Guided Access Started" will briefly appear.
To end Guided Access for an app so it can be exited, do the following:
Quickly press your device's Home button three times to bring up the Guided Access menu.
Enter your four digit passcode when prompted.
Tap the End button in the top left corner of the screen to end Guided Access. A message stating "Guided Access Ended" will briefly appear.
Here's the knowledgebase article of Apple: http://support.apple.com/kb/ht5509

ipad forcing login screen

I've seen a couple of threads regarding the use of login screens but just doesn't require what I need. When my application first launches the login screen is present, they enter in the username/password and is verified on the server. If successful they can go to other sections of the application. As this application contains confidential documents, every time the application goes to sleep or the home button is pressed and upon re-entry I show a UIAlertView to confirm their password.
What I would prefer is that when the application goes to sleep the UIAlertView is shown so I'll leave it as is but when the home button is pressed, I want to force them to go back to the original login screen. I've been playing with the exit(0) but apple strongly advise against that but it forces the application to exit and then when the application opens again the login screen is displayed. I'm try to replicate this functionality without the exit(0).
Terminating your app is probably not the right approach. Consider: How do I programmatically quit my iPhone application?.
There is no API provided for gracefully terminating an iPhone
application. Under the iPhone OS, the
user presses the Home button to close
applications. Should your application
have conditions in which it cannot
provide its intended function, the
recommended approach is to display an
alert for the user that indicates the
nature of the problem and possible
actions the user could take - turning
on WiFi, enabling Location Services,
etc. Allow the user to terminate the
application at their own discretion.
You should reconsider your first approach with the UIAlertView if the use of login screens doesn't meet your needs.

Resources