我是靠谱客的博主 危机八宝粥,最近开发中收集的这篇文章主要介绍ios中while()和 android中的不同之处,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 

ios中while()不能www方式读取文件

void FDJson()
{
using(WWW _load = new WWW("file://"+FileFunc.GetStreamPathRW("FontPreferenceC.json")))
//

{
while(!_load.isDone)
{}
  }
}

安卓却可以这样读取

 

经过修改

IEnumerator FDJson()
{
using(WWW _load = new WWW("file://"+FileFunc.GetStreamPathRW("FontPreferenceC.json")))
//

{
while(!_load.isDone)
{
yield return null;
}
}
}

 

可以在ios下正常读取了

 

 

但是这个要用到IEnumerator 枚举器,很不方便,所以读取文件最好用system.io接口读取

public static string ReadTextFromFile (string path)
{
if (System.IO.File.Exists (path))
{
return System.IO.File.ReadAllText (path, System.Text.Encoding.UTF8);
}
else return null;
}

 

但io在安卓中不适用,因为安卓的文件都是jar压缩格式,所以在安卓中要用www读取文件,

http://answers.unity3d.com/questions/210909/android-streamingassets-file-access.html

So I was never able to figure out if it is possible to use the System.IO.FileInfo class to check the existence of a file that is added to your Android .APK file through the StreamingAssets directory. At this point I really doubt it's possible at all. The reason for this is that the .APK file is an archive, as you may know you can open a .APK file using any archiving utility (WinRAR for example) to inspect it's contents as I touched on above. So the FileInfo class apparently does not support archives like this.

Fortunately the WWW class does support a URI in the style of a JAR URL. So instead I am just pointing my WWW object at the location where the file might be (using the correct JAR URL syntax) and seeing if I come back with an error.

This forums post was extremely insightful in showing how exactly to open a file from the StreamingAssets folder. I'm kind of surprised that this issue isn't better documented, but hopefully in the future this post will save someone a lot of time.

In review:

  1. Don't use System.IO.FileInfo to access files that are archived in your .APK
  2. WWW is your best friend.
  3. The correct URI to access StreamingAssets on Android devices is: "jar:file://" + Application.dataPath + "!/assets/" + fileName

 

 

最后

以上就是危机八宝粥为你收集整理的ios中while()和 android中的不同之处的全部内容,希望文章能够帮你解决ios中while()和 android中的不同之处所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部