简体   繁体   English

Flex 4 mobile ios从浏览器中的应用程序属性打开文件

[英]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)). 我正在应用程序存储目录中保存一个文件,我想通过执行navigateToURL(新的URLRequest(file.nativePath))使用ios浏览器打开它。 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. 请参阅Objective-c / iOS - 使用Safari打开本地html文件, 使用iPad上的Web浏览器在apple.stackexchange.com 上查看本地HTML文件 Basically, the ios security model prevents this. 基本上,ios安全模型可以防止这种情况发生。

What you can do is use StageWebView : 你可以做的是使用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. StageWebView显示在应用程序中所有其他组件的顶部,因此您需要留下一个边距(如上面包含的50像素偏移量),以便为按钮关闭StageWebView。

See also the StageWebView docs 另请参见StageWebView文档

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. 基本上, File.nativePathFile.url都会为您提供一个使用app://app-storage:// (或任意数量的其他)的URL,这两者都与应用程序本身有关。 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. 当您尝试在浏览器或StageWebViewStageVideo打开该链接StageVideo ,该链接将变为相对于浏览器/视频播放器,而不是您的应用程序。 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. 我在很久以前的Adobe论坛帖子中发现了这个(可能被认为是“黑客”,但它有效)。 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. 此文件的URL是文件的完整路径,而不是以任何方式相对于应用程序。 As mentioned by Brian, you may end up needing to use StageWebView instead, but this will give you the proper pathing. 正如Brian所提到的,您可能最终需要使用StageWebView ,但这将为您提供正确的路径。

As a quick note, this does not work on Android if I remember correctly. 作为一个快速说明,如果我没记错的话,这在Android上不起作用。 On Android, you want to use either nativePath or url directly. 在Android上,您希望直接使用nativePathurl But this little workaround will work on iOS (An app I currently have in the app store is using it without issue) 但是这个小小的解决方法可以在iOS上运行(我在应用程序商店中使用的应用程序正在使用它而没有问题)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM