简体   繁体   中英

How to check first run of an AIR application

I want to check my AIR application is running in my system first time or not. Most of my searching lead to one answer that to write a file out side and check the file existing or not. But my requirement is different and if re install the same version again, then it should be a first run. Is there any idea to achieve that?

I am using File.applicationDirectory for several ipad apps and can confirm that all data written to that folder is wiped when the app is uninstalled. Thus being able to load a file previously saved to this folder gives you what you want.

var docDir:File = new File(File.applicationDirectory.nativePath + "/\.\./Documents");  //IOS specific
configFile = docDir.resolvePath("config.xml");
if (configFile.exists) {
  var firstRun:Boolean = false;
  configFile.addEventListener(Event.COMPLETE, onConfigLoaded);
  configFile.load();
}else {
  firstRun = true;
  var configXML:XML = new XML("<?xml version='1.0' encoding='utf-8' ?><config />");

  var fileStream:FileStream = new FileStream();
  fileStream.open(configFile, FileMode.WRITE);
  fileStream.writeUTFBytes(configXML);
  fileStream.close();
}

在与应用程序安装相同的文件夹中创建一个文件,然后在用户卸载应用程序时,该文件也会从C:\\ Program Files \\ yourgame \\ myfile.txt中删除。

I tried a method to write a file in application directory, first time I got a security error(http://forums.adobe.com/thread/209533)I got another method to overcome that and wrote a file inside the application directory. But after uninstalling that file is not deleted.My application folder retains there because i wrote an external file(That i want to store for first run check) inside the folder. Again tried to install the application an error message says folder exist.So i have to manually remove the folder to reinstall the application.if i delete that folder, then my problem is solved,I dont think its a good solution as User have to manually delete the folder for reinstall. Is there any other solution?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM