简体   繁体   中英

Flex 4 mobile ios open a file from application properties in browser

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.

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

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)

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