Skip to main content
Inspiring
Aug 3, 2016 6:30 PM UTC
Answered

Store data's in Ipad

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

This topic is closed to new replies. Start a new post to keep the conversation going.
jadams602
jadams602Correct answer
Inspiring
Aug 4, 2016 3:46 PM UTC

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

  • 3 replies

    jadams602
    jadams602Correct answer
    Inspiring
    Aug 4, 2016 3:46 PM UTC

    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

  • Translate
    rahimhajiAuthor
    Inspiring
    Aug 7, 2016 6:16 AM UTC

    Dear Mr.jadam,

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

    Translate
    deesharm
    Adobe Employee
    Adobe Employee
    Aug 4, 2016 8:52 AM UTC

    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

    Translate