ipad forcing login screen - ios

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.

Related

Killing an iOS app programmatically

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

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.

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

ios sdk show alert without launching the app

I have incorporated custom URL feature in my ios application. I would like to pop an alert on the browser itself when the application is relaunched from a screen other than home screen. I know if the app is relaunched from home screen or not. I am now popping an alert in the application it self. I want to throw the alert with out launching the application may be on the browser itself.
Thanks.
Since you can not do ANY UI stuff without having you app running, this will not be possible.
I think that is not possible, as when you are firing the URL, the control is in iOS Safari app. (Not in our custom app), and whatever you can do is - write code in your app only. So until your app gets launched, your code will not get to run, and alert won't be shown.
I am not sure if there is any other way around, this is just my own thinking.

Prevent application from entering background, requiring a code to close app

I would like to add functionality to my iPad app such that, when the home button is pressed and my app is about to enter the background, a message box pops up requesting a code. Only if the correct code is entered will the application go into the background, otherwise the app will not close.
Is this possible?
Short answer, no it's not possible.

Resources