quit iOS app

There does not seem to be a solution to quit an iOS app. The Quit-command shows, but application.quit gives error: This item does not exist. Thanks!

Under what circumstances would you have your code quit the app ?

You may not quit your app. It is against Apple guidelines and (as far as I know) your app will be rejected if you try to quit.

open event, if there is no internet connection. The star wars game also quits if there is no connection… But no problem, all they get is a warning to switch the internet on…

Thanks!

Problem would be that IF there is no connection a user would see your app appear to start then quit and might assume its crashed

Something to say " you need the internet turned on" and do nothing would be more informative

Then the user at least knows whats going on
And you dont violate Apples guidelines if you want to distribute your app

Understand! Thanks!

[quote=172360:@Nic Kolbe]open event, if there is no internet connection. The star wars game also quits if there is no connection… But no problem, all they get is a warning to switch the internet on…

Thanks![/quote]
Actually the Star Wars game usually crashes if there’s no internet. :stuck_out_tongue:

Ah the magic “return to home screen” functionality in iOS :stuck_out_tongue:

Something to know - if an app crashes on iOS it may look like its just quit - but iOS basically keeps running and doesn’t inform you of this.
You can find the crash logs on the phone when you connect it to your computer

In Xcode I could use

exit(0);

In Ansca Corona

os.exit() 

What is the equivalent in XOJO?
This app is not for app store submission, and I’m not concerned with iOS Human Interface Guidelines. I need to be able to programmatically quit my iOS app. Any pointers?

You double tap the [HOME] key, and swipe the app off the screen…

The only way to abort an iOS app is under the users direct control…

And you said “This app is not for app store submission”… this infers you will install it only on a device that you own?

options

  1. declare into the OS runtime lib for exit as its kind of abnormal for an iOS app to decidedly quit NOT under user direction to do so

  2. raise an exception you deliberately dont catch

Not true Dave. I posted two code examples how to quit an iOS app in other languages, one of them Apples own. It does not follow Apples iOS Human Interface Guidelines, but that doesn’t mean it is not possible.

I’m distributing to multiple devices, Ad-Hoc. Though this could be applied to Apple Enterprise Distribution, I’m in both programs.
There is a valid reason I want to quit the app, under app control, without the need for user interaction.

[quote=238222:@Norman Palardy]options

  1. declare into the OS runtime lib for exit as its kind of abnormal for an iOS app to decidedly quit NOT under user direction to do so
  2. raise an exception you deliberately don’t catch[/quote]
    Thanks Norman. I wasn’t sure if I was missing something. Seems I’ll need to roll my own.

Theres no iOS version of “App.Quit” like in desktop etc otherwise that’d be the answer

declaring into exit seems the simplest

[quote=238249:@Norman Palardy]Theres no iOS version of “App.Quit” like in desktop etc otherwise that’d be the answer

declaring into exit seems the simplest[/quote]

Yeah, and only trick to invoking exit or _exit via declares is that the name needs to be a valid Xojo identifier and the alias field set to the actual function name. Example:

Declare Sub os_exit Lib "libsystem.dylib" Alias "exit" (ret As Int32) os_exit(1)

When I try to build my IOS app with this Declare in it I get this error. This is for an in house enterprise app and we are an enterprise developer so this should not be an issue because we will not be submitting to the App store. Any assistance in how I get this library linked into my project would be greatly appreciated!

ld: framework not found libsystem.dylib

Try:

Declare Sub os_exit Lib "/usr/lib/libSystem.dylib" Alias "exit"(ret As Int32)
os_exit(1)

Thanks Jason, that was the trick. Has anyone else implemented this? It appears it doesn’t really close the app. It takes you to the home screen, but the app is still running if you check for running apps?

You’re welcome Stephen. I think the list you’re referring to is really a list of recently run apps, not currently running apps. That’s because iOS really only runs one app at a time - the foreground app. So even though you’ve quit your app, it will still appear in the list.

Interesting did not know that.