3

我正在通过 Phonegap 开发 iPhone/iPad 应用程序,有没有办法实现一种“单击此处退出应用程序”?我的意思是真正退出,而不是“将其置于后台并转到主屏幕”。

提前致谢。

4

4 回答 4

2

您可以使用以下代码在点击时调整您的应用程序,

device.exitApp()

或者

navigator.app.exitApp()

希望这可以帮助你。

于 2013-04-02T11:53:01.537 回答
1

有没有办法实现一种“单击此处退出应用程序”?

是的,有一种方法可以真正退出应用程序并终止其进程。

但永远不要那样做。不仅因为如果您这样做,Apple 会拒绝您的应用程序。这样做的问题是糟糕的用户体验。iOS 不是桌面操作系统。您有一个用于离开应用程序的主页按钮(同样,应用程序无法完全退出是有原因的)。

从概念上讲,窗口大小不足以维持一个无关紧要的 44x44 像素框架(根据 Apple 的人机界面指南,44 像素是可以舒适触摸的最小尺寸),仅用于退出。

但是,如果您在本次讲座结束后仍想退出,有几种方法:

exit(0);
pthread_kill(pthread_self()); // on the main thread
[[UIApplication sharedApplication] terminateWithSuccess];

等等。其中一些可能在PhoneGap中有一个绑定(如果没有,你自己写一个很容易)。

于 2013-04-02T11:49:31.090 回答
1

您不应该这样做,因为这可能会被视为违反 iOS 人机界面指南,导致您的应用被拒绝。

Always Be Prepared to Stop

**Save the current state when stopping at the finest level of detail possible so that people don’t
lose their context when they start the app again.** For example, if your app displays scrolling data,
save the current scroll position. To learn more about efficient ways to preserve and restore your
app’s state, see “State Preservation and Restoration”.

苹果指南链接:

http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/UEBestPractices/UEBestPractices.html

于 2013-04-02T11:52:58.190 回答
1

在应用程序的 plist 中

 UIApplicationExitsOnSuspend = TRUE

当用户点击主页按钮时,应用程序将退出。不需要按钮,不需要 exit()。

http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23

于 2013-04-02T14:00:40.003 回答