在Parse.com上传文件是';t工作
本文关键字:工作 文件 Parse com | 更新日期: 2023-09-27 18:25:44
我一直在C#中的Unity3D中开发一款游戏。所以我已经将游戏设置为上传游戏保存文件每2分钟分析一次。当我在Unity中运行代码时,它工作得很好,它在本地保存游戏保存文件,每2分钟上传一次到Parse,它还指向玩游戏的用户。虽然当我在移动设备上运行游戏时,文件不会上传,但在过去的半个小时里,我一直在刷新我的解析数据对象,但我仍然没有得到任何东西。
这是代码:
void Start ()
{
if (ParseUser.CurrentUser != null)
{
gapTest = true;
}
}
void Update ()
{
if(gapTest)
{
StartCoroutine(UploadFile());
}
if (uploadSaveFile)
{
OnZipComplete();
uploadSaveFile = false;
}
else if (createNewSaveFile)
{
CreateNewSaveFile();
createNewSaveFile = false;
}
}
IEnumerator UploadFile()
{
gapTest = false;
yield return new WaitForSeconds (120.0F);
if(ParseUser.CurrentUser != null)
{
OnZipComplete();
}
gapTest = true;
}
void OnZipComplete()
{
var query = ParseObject.GetQuery("GameSave").WhereEqualTo("UserObjectId", ParseUser.CurrentUser);
if (existingGameSave == null)
{
query.FindAsync().ContinueWith(t =>
{
IEnumerable<ParseObject> results = t.Result;
int resultCount = 0;
foreach (var result in results)
{
if (resultCount > 0)
{
Debug.LogError("Found more than one save file for user!");
}
else
{
resultCount++;
existingGameSave = result;
uploadSaveFile = true;
}
}
if (resultCount == 0)
{
createNewSaveFile = true;
}
});
}
else
{
UpdateExistingSaveFile();
}
}
private void CreateNewSaveFile()
{
//upload the file to parse
zipPath = Application.persistentDataPath + "/SaveGame.zip";
byte[] data = System.Text.Encoding.UTF8.GetBytes(zipPath);
ParseFile GameSave = new ParseFile("GameSave.zip", data);
var gameSave = new ParseObject("GameSave");
gameSave["UserObjectId"] = ParseUser.CurrentUser;
gameSave["GameSaveFile"] = GameSave;
Task saveTask = gameSave.SaveAsync();
Debug.Log("New Game save file has been uploaded");
}
void UpdateExistingSaveFile()
{
//upload the file to parse
UserIdFile = Application.persistentDataPath + "/UserId.txt";
zipPath = Application.persistentDataPath + "/SaveGame.zip";
byte[] data = System.Text.Encoding.UTF8.GetBytes(zipPath);
ParseFile GameSave = new ParseFile("GameSave.zip", data);
existingGameSave["GameSaveFile"] = GameSave;
Task saveTask = existingGameSave.SaveAsync();
Debug.Log("Existing Game save file has been uploaded");
}
这可能是与安卓设备上的权限有关的问题。
进入构建设置>播放器设置>其他设置,并选中"写入访问权限",默认情况下为内部访问权限,这意味着该路径仅用于开发目的。
尝试将写入访问设置为外部(SD卡)或将Write_EEXTERNAL_STORAGE权限添加到AndroidManifest.xml中。如果您的数据实际上正在设备上写入,请检查SD卡的Android/file/com.your.appid/files。
如果正在写入数据,那么它肯定会上传到parse.com上。