0

I am saving a file on the application storage directory and I would like to open it with the ios browser by doing navigateToURL(new URLRequest(file.nativePath)). But the files does not open. I know it should work because if I navigate to google the browser opens correctly. So the problem is the file path I place in the browser for the file.

Does someone know what is the file path I shoud place on the browser to access the file on the application storage directory.

ketan
  • 19,129
  • 42
  • 60
  • 98
Dave
  • 598
  • 2
  • 4
  • 17
  • What happens if you try to open that file with FileStream.open() and do a trace(fileStream.readUTFBytes(fileStream.bytesAvailable);? – Brian Nov 21 '13 at 16:43
  • How are you creating the file path URL when you try to use navigateToURL? – JeffryHouser Nov 21 '13 at 16:49
  • I used both: navigateToURL(new URLRequest(file.nativePath)) and navigateToURL(new URLRequest(file.url)) neither worked – Dave Nov 21 '13 at 17:29

2 Answers2

1

See Objective-c/iOS - Open local html file with Safari and View local HTML files using web browser on iPad on apple.stackexchange.com. Basically, the ios security model prevents this.

What you can do is use StageWebView:

 var webView:StageWebView = new StageWebView();
 webView.stage = this.stage;
 webView.viewPort = new Rectangle( 0, 50, stage.stageWidth, stage.stageHeight );
 webView.loadURL(file.nativePath); // or file.url

StageWebView displays on top of all other components in your application, so you'll want to leave a margin (like the 50 pixel offset I included above) to leave room for a button to dismiss the StageWebView.

See also the StageWebView docs

Community
  • 1
  • 1
Brian
  • 3,850
  • 3
  • 21
  • 37
  • They will have the same issue with `StageWebView`. The issue is not the file itself, but the path being used. Although I do believe they will have to switch to StageWebView anyway for the reasons you mentioned. – Josh Nov 21 '13 at 18:08
  • @Josh Janusch it works on the desktop debug mode but not when I debug on the device. The browser appears Blank. I don't understand. So I am using webView like Brian said because of security issues. I tried webView.loadURL(file.nativePath) and file.url. Finally, I tried with the hack from Josh. Any other suggestion? – Dave Nov 22 '13 at 08:57
1

You are correct that your path is incorrect. Basically, File.nativePath and File.url will both give you a URL that uses app:// or app-storage:// (or any number of others), both relative to the app itself. When you try to open that link in a browser or in StageWebView or in StageVideo, the link becomes relative to the browser/video player, rather than your app. That is why you cannot link to the files properly.

There is a simple fix, thankfully. I found this (which may be considered a "hack", but it works) in an Adobe Forums post a long time ago. I wish I had a source, but I don't:

trace( new File( file.nativePath ).url );

Try that. It basically creates a new File using the actual native path of the file. The URL of this file is the full path to the file, rather than being relative to the app in any way. As mentioned by Brian, you may end up needing to use StageWebView instead, but this will give you the proper pathing.

As a quick note, this does not work on Android if I remember correctly. On Android, you want to use either nativePath or url directly. But this little workaround will work on iOS (An app I currently have in the app store is using it without issue)

Josh
  • 8,079
  • 3
  • 24
  • 49
  • Ok, the problem is that I am trying to open an xml file which should be transformed with an xsl file. This works on ADL but not on the sandbox of my ipad. Whith a normal HTML file it works. – Dave Nov 22 '13 at 09:34
  • Do you guys know a way to apply an XSL transformation offline with ActionScript. – Dave Nov 22 '13 at 09:35