In the Unity Editor, the app works well with the Firebase storage. Images are downloaded and used. When we build the Unity app for iOS, it gave errors when it tries to download the images from the Firebase Storage. I think, this is an issue to writing permission, and I have no clue on how to solve it from Unity code
What was done
- Clean Build Folder
- Update to Latest Firebase packages
- Refer to these SO questions:
- Firebase Storage download to local file error
- Images not downloading from Firebase Storage
- Error when downloading from Firebase storage
- These threads aren't using Unity, and I don't know how these can be applied to the issue at hand
Code
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;
}
});
Errors
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)
The errors is not helpful and to make it worse, I don't know how to find the debug log mentioned at Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
. I've opened the Xcode project, and see no Runtime folder (even after showing hidden items)
Any idea how to solve this issue?
CodePudding user response:
The solution was certainly not obvious.
Apparently, all I need to do was to prepend file:///
to the savePath variable, like so:
string savePath = "file:///" Application.persistentDataPath "/" data.banner