Unity iOS build in Xcode 无法写入从 Firebase 存储下载的图像
Unity iOS build in Xcode cannot write downloaded images from Firebase Storage
在 Unity 编辑器中,该应用程序与 Firebase 存储配合得很好。图像被下载和使用。当我们为 iOS 构建 Unity 应用程序时,它在尝试从 Firebase 存储下载图像时出错。我想,这是写权限的问题,我不知道如何从 Unity 代码中解决它
做了什么
- 清理构建文件夹
- 更新到最新的 Firebase 包
- 参考这些SO问题:
- 这些线程没有使用 Unity,我不知道如何将它们应用于手头的问题
代码
string savePath = Application.persistentDataPath + "/" + data.banner;
StorageReference storageRef = storage.GetReference(data.banner);
Task task = storageRef.GetFileAsync(savePath, new StorageProgress<DownloadState>((DownloadState state) => {
GetComponent<DatabaseManager>().UpdateProgress(state.BytesTransferred, state);
}), CancellationToken.None);
task.ContinueWithOnMainThread(resultTask => {
if (!resultTask.IsFaulted && !resultTask.IsCanceled && resultTask.IsCompleted) {
floorCounter++;
if (floorCounter == floors.Count) {
isFloorComplete = true;
}
} else {
Debug.Log(resultTask.Exception.ToString());
errorCaught = true;
return;
}
});
错误
System.AggregateException: One or more errors occurred. ---> Firebase.Storage.StorageException: An unknown error occurred
--- End of inner exception stack trace ---
---> (Inner Exception #0) Firebase.Storage.StorageException: An unknown error occurred<---
<>c__DisplayClass3_1:<DownloadImages>b__3(Task)
System.Action`1:Invoke(T)
Firebase.Extensions.<ContinueWithOnMainThread>c__AnonStorey1:<>m__0()
System.Func`1:Invoke()
Firebase.<RunAsync>c__AnonStorey1`1:<>m__0()
System.Action:Invoke()
Firebase.ExceptionAggregator:Wrap(Action)
Firebase.Dispatcher:PollJobs()
Firebase.Platform.FirebaseHandler:Update()
(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
这些错误没有帮助,更糟糕的是,我不知道如何找到 Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
中提到的调试日志。我打开了 Xcode 项目,但没有看到运行时文件夹(即使在显示隐藏项之后)
知道如何解决这个问题吗?
解决方案当然不是很明显。
显然,我需要做的就是将 file:///
添加到 savePath 变量之前,如下所示:
string savePath = "file:///" + Application.persistentDataPath + "/" + data.banner
在 Unity 编辑器中,该应用程序与 Firebase 存储配合得很好。图像被下载和使用。当我们为 iOS 构建 Unity 应用程序时,它在尝试从 Firebase 存储下载图像时出错。我想,这是写权限的问题,我不知道如何从 Unity 代码中解决它
做了什么
- 清理构建文件夹
- 更新到最新的 Firebase 包
- 参考这些SO问题:
- 这些线程没有使用 Unity,我不知道如何将它们应用于手头的问题
代码
string savePath = Application.persistentDataPath + "/" + data.banner;
StorageReference storageRef = storage.GetReference(data.banner);
Task task = storageRef.GetFileAsync(savePath, new StorageProgress<DownloadState>((DownloadState state) => {
GetComponent<DatabaseManager>().UpdateProgress(state.BytesTransferred, state);
}), CancellationToken.None);
task.ContinueWithOnMainThread(resultTask => {
if (!resultTask.IsFaulted && !resultTask.IsCanceled && resultTask.IsCompleted) {
floorCounter++;
if (floorCounter == floors.Count) {
isFloorComplete = true;
}
} else {
Debug.Log(resultTask.Exception.ToString());
errorCaught = true;
return;
}
});
错误
System.AggregateException: One or more errors occurred. ---> Firebase.Storage.StorageException: An unknown error occurred
--- End of inner exception stack trace ---
---> (Inner Exception #0) Firebase.Storage.StorageException: An unknown error occurred<---
<>c__DisplayClass3_1:<DownloadImages>b__3(Task)
System.Action`1:Invoke(T)
Firebase.Extensions.<ContinueWithOnMainThread>c__AnonStorey1:<>m__0()
System.Func`1:Invoke()
Firebase.<RunAsync>c__AnonStorey1`1:<>m__0()
System.Action:Invoke()
Firebase.ExceptionAggregator:Wrap(Action)
Firebase.Dispatcher:PollJobs()
Firebase.Platform.FirebaseHandler:Update()
(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
这些错误没有帮助,更糟糕的是,我不知道如何找到 Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
中提到的调试日志。我打开了 Xcode 项目,但没有看到运行时文件夹(即使在显示隐藏项之后)
知道如何解决这个问题吗?
解决方案当然不是很明显。
显然,我需要做的就是将 file:///
添加到 savePath 变量之前,如下所示:
string savePath = "file:///" + Application.persistentDataPath + "/" + data.banner