2017-04-17 11 views
0

Iveにはjsonをダウンロードする機能があり、デバイスにコピーを保存しようとしています。それはアンドロイドとエディタで正常に動作します。私の指を置くことはできません。 IpadはIOS 10を実行しており、何かを追加すると統一された設定は9以上になります。IOSファイルシステムへの書き込みエラーは、アンドロイドとエディタで動作します

以下は、ユニコード+ xcodeのエラーです。

MonoDevelopの

using UnityEngine; 
using System.Collections; 
using System; 
using System.IO; 
using System.Collections.Generic; 
using LitJson; 


public class loadJSONHome : MonoBehaviour { 

public string url; 
public string url2; 
private string jsonString; 
public static loadJSONHome instance; 
public GameObject preloader; 

void Awake(){ 
    if(instance==null){ 
    instance = this; 
    } 

} 
void Start(){ 
     WWW www2 = new WWW(url); 
     StartCoroutine(WaitForRequest(www2)); 
    // preloader.SetActive(true); 

} 

IEnumerator WaitForRequest(WWW www2){ 
    yield return www2; 

    // check for errors 
    if (www2.error == null) 
    { 
    //SAVE JSON FROM ONLINE LOCALLY 
    jsonString = www2.text; 

     writeStringToFile(jsonString, "FoodnDrink_Cats.json"); 

    writeListings(); 
    } else { 
     Debug.Log("WWW2 Error: "+ www2.error); 
    }  
} 




    void writeListings(){ 

    WWW www3 = new WWW(url2); 
     StartCoroutine(WaitForRequest2(www3)); 
    } 

IEnumerator WaitForRequest2(WWW www3){ 
    yield return www3; 

    // check for errors 
    if (www3.error == null) 
    { 
    //SAVE JSON FROM ONLINE LOCALLY 
    jsonString = www3.text; 

     writeStringToFile(jsonString, "listings_FoodnDrink.json"); 

    } else { 
     Debug.Log("WWW3 Error: "+ www3.error); 
    } 

    //preloader.SetActive(false); 
    } 











    public void writeStringToFile(string str, string filename){ 
     #if !WEB_BUILD 
      string path = pathForDocumentsFile(filename); 
      FileStream file = new FileStream (path, FileMode.Create, FileAccess.Write); 

      StreamWriter sw = new StreamWriter(file); 
      sw.WriteLine(str); 

      sw.Close(); 
      file.Close(); 
     #endif 
    } 

    public string readStringFromFile(string filename){ //, int lineIndex) 
     #if !WEB_BUILD 
      string path = pathForDocumentsFile(filename); 

      if (File.Exists(path)) 
      { 
       FileStream file = new FileStream (path, FileMode.Open, FileAccess.Read); 
       StreamReader sr = new StreamReader(file); 

      string str = null; 
      str = sr.ReadToEnd(); 

      sr.Close(); 
      file.Close(); 

      return str; 
     }else{ 
     return null; 
     } 
     #else 
     return null; 
     #endif 
    } 


    public string pathForDocumentsFile(string filename){ 
     if (Application.platform == RuntimePlatform.IPhonePlayer) 
     { 
      string path = Application.dataPath.Substring(0, Application.dataPath.Length - 5); 
      path = path.Substring(0, path.LastIndexOf('/')); 
      return Path.Combine(Path.Combine(path, "Documents"), filename); 
     }else if(Application.platform == RuntimePlatform.Android){ 
     string path = Application.persistentDataPath; 
      path = path.Substring(0, path.LastIndexOf('/')); 
      return Path.Combine (path, filename); 
     }else { 
      string path = Application.dataPath; 
      path = path.Substring(0, path.LastIndexOf('/')); 
      return Path.Combine (path, filename); 
     } 
    } 





} 

XCODE

場所サービス更新が有効になっていません。最後の場所を問い合わせる前にLocationService.statusを確認してください。

IsolatedStorageException:パス "/var/containers/Bundle/Application/BC5FA0A8-9767-4689-8707-EBB7FA1886F5/Documents/FoodnDrink_Cats.json"の一部が見つかりませんでした。 at System.IO.FileStream..ctor(System.String.FileStream.ctorのパス、FileModeモード、FileAccessアクセス、FileShare共有、Int32 bufferSize、Boolean匿名、FileOptionsオプション)[0x00000] in:0 at System.IO.FileStream..ctor (System.Stringパス、FileModeモード、FileAccessアクセス、FileShare共有、Int32 bufferSize、Boolean isAsync、ブール匿名)[0x00000] in 0: at System.IO.FileStream..ctorアクセス)[0x00000]で:loadJSONHome.writeStringToFileで0 (可能System.String STR、ファイル名可能System.String)[0x00000]で:loadJSONHome + c__Iterator5.MoveNext(AT 0 )[0x00000]:0

(ファイル名:現在il2cppでは利用できません。ライン:-1)

ヘルプありがとうございます。

+0

あなたは、私は信じているあなたのコード内に複数の問題を抱えています。位置情報サービスパークについては、次の操作を行ってください。http://stackoverflow.com/a/24063578/1035008 –

+0

ありがとうございました。問題のデバッグコードがほんの少しの未使用の変数であれば、私はきれいにする必要があります。問題は、あなたが助けてくれた位置情報サービスであり、主な問題は隔離されたストレージラインです。あなたがパスの検索機能からその1つを助けることができるなら、それは評価されるでしょう。 – Diego

+0

それは動作しませんでした:(私はユニティバージョンとxcodeを更新して、どのようにパンが出るのか見てみよう – Diego

答えて

0

私はyoutubeビデオ(最後に掲載)の助けを借りてそれを理解しました。

リンゴの隔離と承認ファイルの問題を回避するために、メソッドをバイナリデータ形式で保存するように変更しました。これはまた多くのクリーナーです。ここで

はコードです:

using UnityEngine; 
using System.Collections; 
using System; 
using System.Runtime.Serialization.Formatters.Binary; 
using System.IO; 


public class loadJSONHome : MonoBehaviour { 

    public string url; 
    public string url2; 
    private string jsonString; 
    public static loadJSONHome instance; 
    public GameObject preloader; 

    void Awake(){ 
     if(instance==null){ 
     instance = this; 
     } 

    } 
    void Start(){ 
      WWW www2 = new WWW(url); 
      StartCoroutine(WaitForRequest(www2)); 
      preloader.SetActive(true); 

    } 

    IEnumerator WaitForRequest(WWW www2){ 
     yield return www2; 

     // check for errors 
     if (www2.error == null) 
     { 
     //SAVE JSON FROM ONLINE LOCALLY 
     jsonString = www2.text; 

      Save(jsonString, "FoodnDrink_Cats.json"); 

     writeListings(); 
     } else { 
      Debug.Log("WWW2 Error: "+ www2.error); 
     }  
    } 




    void writeListings(){ 

     WWW www3 = new WWW(url2); 
      StartCoroutine(WaitForRequest2(www3)); 
     } 

    IEnumerator WaitForRequest2(WWW www3){ 
     yield return www3; 

     // check for errors 
     if (www3.error == null) 
     { 
     //SAVE JSON FROM ONLINE LOCALLY 
     jsonString = www3.text; 

      Save(jsonString, "listings_FoodnDrink.json"); 

     } else { 
      Debug.Log("WWW3 Error: "+ www3.error); 
     } 

     preloader.SetActive(false); 
    } 



    public void Save(string json, string filename){ 

     BinaryFormatter bf = new BinaryFormatter(); 
     FileStream file = File.Open(Application.persistentDataPath + "/" +filename, FileMode.Create); 

     myFile current = new myFile(); 
     current.theFile = json; 

     bf.Serialize(file, current); 
     file.Close(); 


    } 


    public string Load(string filename){ 

     if(File.Exists(Application.persistentDataPath + "/" + filename)){ 
      BinaryFormatter bf = new BinaryFormatter(); 
      FileStream file = File.Open(Application.persistentDataPath + "/" + filename, FileMode.Open); 
      myFile data = (myFile)bf.Deserialize(file); 
      file.Close(); 
      string fileinfo = data.theFile; 
      return fileinfo; 
     }else{ 
      return null; 
     } 
    } 




} 

[Serializable] 
class myFile { 

    public string theFile; 


} 

はここでYouTubeのビデオです:https://www.youtube.com/watch?v=yxziv4ISfys

関連する問題