iPhone - 使用PhoneGap检测首次启动

5
我正在尝试检测新安装应用程序的首次启动,并显示应用程序的许可协议。用户必须接受许可协议或离开应用程序。
有人知道如何在Phonegap中实现这一点吗?我已经搜索了相关主题,但似乎没有找到任何相关的信息。
谢谢。
2个回答

19
您可以使用本地存储来跟踪应用程序启动次数。
var applaunchCount = window.localStorage.getItem('launchCount');

//Check if it already exists or not
if(applaunchCount){
   //This is a second time launch, and count = applaunchCount
}else{
  //Local storage is not set, hence first time launch. set the local storage item
  window.localStorage.setItem('launchCount',1);

  //Do the other stuff related to first time launch
}

谢谢提供信息...我不是很懂技术,所以这个能用JavaScript实现并在第一次启动时显示自定义消息吗?即使这只是一个<div>元素,仅在第一次启动时显示,那也是完美的。 - ZodTron
是的...您可以在else部分(即第一次启动的情况)显示自定义消息。 - Manish Kumar

1
现在iOS可能会清除localStorage,因此您不能指望它是持久的。
对于真正的持久存储,一个选项是文件系统插件。

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file

请注意,如果您的应用被卸载,您的持久性文件很可能也会被删除。对于这个应用程序来说,这可能是可以接受的。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接