Programmatically suspend/close the app - ios

How can I suspend/close my iPad app programmatically? I wanted to show the terms of use on app start up. If user presses the Accept button the app should continue. If user presses the Decline button the app should be suspended/closed.
PS : The app is built using Titanium Appcelerator framework.

you could try calling exit() but, to be honest, i doubt that the behaviour you want is desirable. i haven't seen any other apps do it - i'm not sure it'd be considered acceptable by Apple.

You never exit from an iPhone or iPad application.
If it does apple takes it as a crash and surely reject your application.
In your case, the best solution will be displaying another screen which display a message like: "You cannot access the application until you accept the terms" or something like that.

You can use exit(0); whenever you want to exit the app. I have implemented this code in my project and it works perfectly fine for me.

Related

iOS development, Natively open an App in my App

I have a project where I have to open an App like Facebook inside my App.
I know the URL Scheme but it is not what I want. I don't want to left my App and have like a webview but for a native app (Facebook for exemple).
Same behavior than.
Is it possible ?
Thx a lot :-)
No, this is not possible. At least not on a non-jailbroken device (there might be hacks that can be done on a jailbroken device to achieve this that I'm not aware of).
No this is not possible. You cant open another app inside of your current app. You can open an app from within an app but you cant frame that app inside of yours.
Other than the fact that apple has prohibited and not made this available, it also will cause a poor guest experience. The apps are designed to run on the users device, not a smaller screen.
it's impossible to open another app in a running app, but you can open a webapp

ios 8 openUrl itms-services does not exit current app

In iOS 6 or 7, the app exit to the home screen when I call UIApplication openUrl with a url of itms-services://XXXX to install a new version of my app (using enterprise deployment with ipa files).
In iOS 8, this is no longer the case. Now the app continue running just as nothing has happened, but if I go the home screen, I can see my app icon grayed out, with a downloading pie chart about 66% completed and the text "Downloading..." below. If I now wait for a while (less than a minute), the application is installed correctly and I can start my app again.
Has anyone else experienced this behavior? Have anyone seen any documentation regarding this? I can accept behavioral changes as long as it is documented, but I haven't seen any documentation regarding this.
While forcing the app to crash will technically work, a much better solution (allowing the user to retain the state of the application) would be to simply background the app launching the itms-services link by executing the following.
[[UIApplication sharedApplication] performSelector:#selector(suspend)];
We use this in an app used for distributing test builds to our testers and it works very well, and eliminates the confusion of a tester trying to install an app and having the app stay in front. It also allows them to return to our distribution app and have it pick up where they were.
Yes, you also get the same behaviour when clicking a download link in safari now on iOS8.
I'm not sure why they introduced this change but there isn't really a way around it (unless you force your app to crash with something like exit(0);)
Also, the itms-services url scheme is undocumented and is technically a private api. From experience, you're not allowed to submit apps to the App Store that use it.
I have experienced a similar thing. I have a web page for our internal app store and when I tap on the link I do get a prompt asking if I want to install and when I say yes safari just sits there. The app is downloading on the home screen but under IOS 7 safari would be pushed to the background and you could see where your app is being downloaded to and its progress. Now it appears like nothing is happening. I would love to correct this. Perhaps something has changed in the .plist files the itms-services protocol uses. This protocol is not private it is just reserved for enterprise deployments.

Prevent an ios app from clossing

I am currently developing an ios app for a localization company. The company provides ipads to all his employees so this new app that i'm developing can keep track of them (in case of an emergency and to know if they are really working).
I already finished the app and everything is working fine but now the problem is that anyone can close the app and "hide" his position from us.
It is possible to do something about this?
Also it is possible to start an app on boot. Something like this but on Ios.
Is there anyway to "lock" the app so it can't be closed and only sent to background?
Thanks
EDIT
I tried with the guided access but the employees also need to use other apps (like safari) to do their work. Not only mine. I tried this and effectively you can't close the app but also you can't access other app. Or am I doing it wrong? I want to allow my app to be in background but not close. Sorry if i did not explain myself well.
Many duplicates of this...
Settings - General - Accessibility - Guided Access.
Turn it on and you can limit what the iPad can do.
You can also stop it from closing apps.

Quit application in titanium (iOS)

What is the equivalent for iOS to:
win.close();
var activity = Titanium.Android.currentActivity;
activity.finish();
Thanks!
There isn't (in Titanium). Further, Apple explicitly discourages this:
"An iOS app never displays a Close or Quit option" - Apple, HIG p27
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/MobileHIG.pdf
There are existing SO answers regarding this:
On the iPhone there is no concept of quitting an app. The only action
that should cause an app to quit is touching the Home button on the
phone, and that's not something developers have access to.
According to Apple, your app should not terminate on its own. Since
the user did not hit the Home button, any return to the Home screen
gives the user the impression that your app crashed. This is
confusing, non-standard behavior and should be avoided.
See existing SO answer here: Proper way to exit iPhone application?
If, after all this, you want a non-standard, will-probably-get-your-app-rejected solution (or if your app isn't destined for the app store, and will be distributed privately through enterprise distribution or personal use), you can create a module that calls [[NSThread mainThread] exit].
There is no way to close iOS application using just Titanium SDK. If you really need that you have to create your own small Titanium Module with just one method:
-(id)example:(id)args
{
// example method
exit(0);
return #"Application Exit";
}
However, remember that calling exit() is strongly not recommended for iOS applications and can lead to rejection from App Store.

iOS - kill the app with a button?

I have an app that runs for a while, but needs to be reset every day, because it's lifecycle is a bit different than most other apps. It seems that the easiest way to do this is to kill the app and re-launch it.
I found a solution that kills the app when the home button is tapped:
In your application's Info.plist, add a boolean key
UIApplicationExitsOnSuspend with the value YES
This is not something that I want to do. I need to give the user an option to kill/reset the app before it is used. I can certainly ask the user to double tap the home key and kill the app with a long press>x. Yet this is too complex for some users.
Another simple solution would be to have a button do something crashworthy, like divide by 0, although I'm not sure if the app store would penalize my app for "crashing" every single day for all users.
Has anyone found a way to add an "exit" button to an iPhone app? In android, I could do system.exit(0), which worked. What's the iPhone alternative?
iOS Human Interface Guide says -
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. ...
exit(0); can terminate the application (0 is a normal code), but Apple don't like this approach, and the application would be rejected in review.

Resources