• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Store data's in Ipad

Participant ,
Aug 03, 2016 Aug 03, 2016

Copy link to clipboard

Copied

Dear Friends,

iam creating an IOS app using Air for IOS. i want to store data in txt file and retrieve it. Iam using the following code:

import flash.filesystem.*;
import flash.events.MouseEvent;
var cacheDir: File = null;
var tempDir: File = null;

//Initialize the Objects with proper paths.
var str: String = File.applicationDirectory.nativePath;
cacheDir = new File(str + "//Library/Caches");
tempDir = new File(str + "//tmp");
var fr: FileStream = new FileStream();
fr.open(cacheDir.resolvePath("myCache.txt"), FileMode.WRITE);
fr.writeUTFBytes("works");
fr.close();

btn.addEventListener(MouseEvent.CLICK, btn_click)

function btn_click(event: MouseEvent) {
var fw: FileStream = new FileStream();
fw.open(cacheDir.resolvePath("myCache.txt"), FileMode.READ);
txt.text = fw.readUTFBytes(4);
fw.close();
}

it works fine in my desktop. when i compile and intall in ipad, it is not workign pls help me what should i do to make it work. i want to store data's in Ipad..

Thanks in Advance,

Syed Abdul Rahim

TOPICS
Development

Views

383

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Aug 04, 2016 Aug 04, 2016

Just to further clarify the difference between your original code and the sample above that works, you are trying to write a file using File.applicationDirectory. That is a read-only directory on iOS (and normally other platforms as well, as mentioned in the docs for File: File - Adobe ActionScript® 3 (AS3 ) API Reference  )

You shouldn't ever try to write into File.applicationDirectory you should at least use File.applicationStorageDirectory, and if you need cache content consider using File.cac

...

Votes

Translate

Translate
Adobe Employee ,
Aug 04, 2016 Aug 04, 2016

Copy link to clipboard

Copied

Hi Syed,

I tried with a sample application for iPad and it successfully writes data on ipad:

I used below lines of actionscript code:

private function writeLogToFile() : void

      {

         logArray.reverse();

         fs = new FileStream();

         if(Capabilities.os.search("Linux") != -1)

         {

            fs.open(File.userDirectory.resolvePath("test.txt"),"append");

         }

         else

         {

            if(!File.documentsDirectory.resolvePath("Logs").exists)

            {

               File.documentsDirectory.resolvePath("Logs").createDirectory();

            }

            fs.open(File.documentsDirectory.resolvePath("Logs/playerinstancemanagement.txt"),"append");

         }

         while(logArray.length > 0)

         {

            fs.writeUTFBytes(logArray.pop() + "\n");

         }

         fs.close();

  

  if(Capabilities.os.search("iPhone")!=-1){

  fs.open(File.documentsDirectory.resolvePath("Logs/done.txt"),FileMode.APPEND);

  fs.writeUTFBytes("done");

  fs.close();

  }else {

  fs.open(File.getRootDirectories()[0].resolvePath("/sdcard/done.txt"),FileMode.APPEND);

  fs.writeUTFBytes("done");

  fs.close();

  

  }

}

Thanks,

Adobe AIR Team

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 04, 2016 Aug 04, 2016

Copy link to clipboard

Copied

Just to further clarify the difference between your original code and the sample above that works, you are trying to write a file using File.applicationDirectory. That is a read-only directory on iOS (and normally other platforms as well, as mentioned in the docs for File: File - Adobe ActionScript® 3 (AS3 ) API Reference  )

You shouldn't ever try to write into File.applicationDirectory you should at least use File.applicationStorageDirectory, and if you need cache content consider using File.cacheDirectory. All those helper static File.

  • Directory properties do all the work for you to chose the right folder no matter what platform.
  • If you are curious where those directories resolve on various platforms there is a nice summary here:

    Adobe Flash Platform * Working with File objects in AIR

    Votes

    Translate

    Translate

    Report

    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Participant ,
    Aug 06, 2016 Aug 06, 2016

    Copy link to clipboard

    Copied

    LATEST

    Dear Mr.jadam,

    Thanks a lot... It's working fine. Problem solved. Thanks a lot.

    Votes

    Translate

    Translate

    Report

    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines