【问题标题】:Phonegap: force an app to quit instead of running in backgroundPhonegap:强制应用退出而不是在后台运行
【发布时间】:2013-04-02 11:40:04
【问题描述】:

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

提前致谢。

【问题讨论】:

  • 不要这样做,你的应用会被拒绝。

标签: iphone ipad cordova quit


【解决方案1】:

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

device.exitApp()

navigator.app.exitApp()

希望对你有所帮助。

【讨论】:

  • 谢谢。其他答案中的所有讲课都很烦人;有时你确实需要让他们退出。
【解决方案2】:

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

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

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

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

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

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

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

【讨论】:

    【解决方案3】:

    您不应该这样做,因为这可能会被视为违反 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

    【讨论】:

      【解决方案4】:

      在应用程序的 plist 中放

       UIApplicationExitsOnSuspend = TRUE
      

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多