Skip to main content
Inspiring
July 22, 2011
Question

Creating an iOS App with File Sharing Activated

  • July 22, 2011
  • 6 replies
  • 6321 views

From what I can decipher, the only way for a user to retrieve a document created by an iOS app is through iTunes, but only if the app has file sharing activated.

Is there a way to create an iOS app in Flash CS5.5 and make it a file sharing app?

This topic has been closed for replies.

6 replies

Participating Frequently
August 24, 2011

Alright. I will try.

Do you have opened a "FileStream" in your code and used it to save?

random_1_Author
Inspiring
August 24, 2011

No, I just used the copyTo() function. It's in the fourth post in this thread.

I would use copyTo() first, just to see if you can get that to work.

Participating Frequently
August 24, 2011

I tried your code but I get an error using a private function…

random_1_Author
Inspiring
August 24, 2011

If you're pasting the code to a timeline script, you can just delete the word "private".

You'll need a button on the stage with an instance name -- copy_btn would work -- and then add this:

copy_btn.addEventListener(MouseEvent.CLICK, eButtonClicked);

Participating Frequently
August 24, 2011

Hey random(1)

would you mind posting the complete code?

I have a similar problem. I succeeded in activating file sharing but I don't get any file saved.

Thanx.

random_1_Author
Inspiring
August 24, 2011

devoti,

Did you verify that the file you want to share is in File.documentsDirectory?

You can use the code from my previous post to list the files there.

July 27, 2011

I used the following code for sharing files to documents directory, and it works just fine. I am able to access the files copied by the app.

I made this app using Flash Builder. I will share another one using Flash Pro, soon.

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
          xmlns:s="library://ns.adobe.com/flex/spark" title="Share File">
     <fx:Declarations>
          <!-- Place non-visual elements (e.g., services, value objects) here -->
     </fx:Declarations>
     
     <fx:Script>
          <![CDATA[
               public function shareFile():void
               {
                              var file:File = File.applicationDirectory.resolvePath("original.swf");
                    var dest:File = File.documentsDirectory.resolvePath("copy.swf");
                    
                    file.copyTo(dest, true);
                    
                    input.text = "File Written";
               }
          ]]>
     </fx:Script>
     <s:TextArea id="input" x="216" y="89" width="336" height="59"/>
     <s:Button id="button" x="292" y="220" width="184" height="50" label="Share Data" click="shareFile()"/>
</s:View>

Can you please share the app/more details about the issue in the meanwhile?

random_1_Author
Inspiring
July 27, 2011

Hi Abhishake,

For no apparent reason, it's now working -- the file test.txt is showing up in the iTunes File Sharing Documents pane.

The only change I made to the code was to do another check to verify the file was getting copied to File.documentsDirectory. In this new check, the app displays a list of the Document files in status_txt. After the try/catch statement in the code listed above, the if(ok) statement now looks like this:

            if (ok)
            {   
                var documentsDirectoryContents:Array = File.documentsDirectory.getDirectoryListing();
                var fileNames:Array = [];
                var item:File;
                for each(item in documentsDirectoryContents)
                {
                    fileNames.push(item.name);
                }
               
                status_txt.text = "Files in " + File.documentsDirectory.nativePath + ":" + "\n" + fileNames.join(", ");
            }

The rest of the code, app settings, etc. is completely unchanged. I have no idea if this new check made any difference...maybe it nudged the iPad into doing some internal update which then resulted in the shared file showing up in iTunes.

I'm testing on Windows 7 with a borrowed iPad 1.

Thanks again for taking the time to look into this problem. It's helpful to know that the location for shared files should be File.documentsDirectory instead of File.applicationStorageDirectory.

July 26, 2011

The app-xml's iPhone InfoAdditions looks fine, and you should be able to access the shared files, using this.

Can you please share the code/snippet you are using to write the files to the Application Documents directory?

random_1_Author
Inspiring
July 26, 2011

Hi,

In my test app, there's one button and one dynamic text field. Here's the button click handler:

        private function eButtonClicked(e:MouseEvent):void
        {
            status_txt.text = "Attempting file copy";
           
            var source:File = File.applicationDirectory.resolvePath("test.txt");
            var destination:File = File.documentsDirectory.resolvePath( "test.txt" );
            //var destination:File = File.applicationStorageDirectory.resolvePath( "test.txt" );


            var ok:Boolean = true;
           
            try
            {
                source.copyTo( destination, true );
            }
            catch (err:Error)
            {
                status_txt.text = "Error copying file: " + err.message;
                ok = false;
            }
           
            if (ok)
            {
                status_txt.text = "File was copied";
            }
        }


Clicking the button results in status_txt displaying "File was copied".

Any help would be greatly appreciated.

Do you have a working example created with Flash CS Pro 5.5 (and the version of AIR 2.7 which was compiled on June 28, 2011)?

random_1_Author
Inspiring
July 25, 2011

Some progress, but still not there.

I created a test app and added the UIFileSharingEnabled key to the -app.xml file's <iPhone><InfoAdditions> node. For an iPad, it looks like this:

<iPhone>
    <InfoAdditions>
      <![CDATA[<key>UIFileSharingEnabled</key><true/><key>UIDeviceFamily</key><array><string>2</string></array>]]>
    </InfoAdditions>
    <requestedDisplayResolution>standard</requestedDisplayResolution>
  </iPhone>

After installing the app, it is now showing up in iTunes in the list of file sharing apps. However, the txt file I copied from File.applicationDirectory to both File.applicationStorageDirectory and File.documentsDirectory is not showing up in the iTunes <App> Documents pane when I select the app.

I wrapped the copyTo() function in a try/catch statement to verify that the txt file is being copied.

Stumped.