在Cordova中退出应用程序无法清除服务器上的会话

I use Cordova to build an online application, i use some session variables on my server(php). when i exit of this app, the sessions still exists on my server. how can i fix it to unset all of sessions automatically? here is my package.json:

{
  "name": "helloworld",
  "displayName": "HelloCordova",
  "version": "1.0.0",
  "description": "A sample Apache Cordova application that responds to the deviceready event.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Apache Cordova Team",
  "license": "Apache-2.0",
  "dependencies": {
    "cordova-android": "^7.1.4",
    "cordova-browser": "^5.0.4",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-dialogs": "^2.0.1",
    "cordova-plugin-inappbrowser": "^3.0.0",
    "cordova-plugin-nativestorage": "^2.3.2",
    "cordova-plugin-network-information": "^2.0.1",
    "cordova-plugin-share": "^0.1.3",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-plugin-x-toast": "^2.7.2"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-dialogs": {},
      "cordova-plugin-nativestorage": {},
      "cordova-plugin-device": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-x-toast": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-network-information": {},
      "nl.madebymark.share": {}
    },
    "platforms": [
      "browser",
      "android"
    ]
  }
}

1个回答



您正在为Android和iOS寻找本机 onDestroy </ code>和 applicationWillTerminate </ code>函数 , 分别。 尝试通过添加这些关键字来搜索插件。 这些事件似乎存在一些cordova插件:</ p>


  • https://github.com/agamemnus/cordova-plugin-ondestroy </ li>
  • https://github.com/bsorrentino/cordova-broadcaster </ li>
    </ ul>

    但是,我还没有检查过 他们的有效性。 当 WebView </ code>应用程序通过cordova桥接收事件时,应用程序实际上可能已经被破坏了。</ p>

    另一方面,为什么 不仅仅是在您的应用程序中保留会话令牌? 只需将其妥善存放在某处。 每次关闭应用程序时用户无需登录这一事实是一个很好的功能,而不是错误。</ p>
    </ div>

展开原文

原文

You are looking for the native onDestroy and applicationWillTerminate functions for Android and iOS, respectively. Try searching for plugins by adding those keywords. It seems some cordova plugins exist for these events:

However, I haven't checked the validity of them. There's a good chance the application may actually be already destroyed by the time the event is received by your WebView application over the cordova bridge.

On another note, why not just persist the session token in your app as well? Just store it somewhere securely. The fact that the user doesn't have to log in each time the app is closed is a great feature, not a bug.

dsgft1486
dsgft1486 谢谢你的回答,但我必须在服务器上使用一些会话,我认为当服务器保存所有会话时,它的内存可能已满! 我只需要在离开应用程序时自动清除所有服务器会话。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐