initial commit, iOS network native library
This commit is contained in:
30
Network/Platforms/iOS/Tasks/DownloadTask.cs
Normal file
30
Network/Platforms/iOS/Tasks/DownloadTask.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Foundation;
|
||||
|
||||
namespace Blahblah.Library.Network;
|
||||
|
||||
public class DownloadTask<T> : ContentTask<T, bool>
|
||||
{
|
||||
public string FilePath { get; }
|
||||
|
||||
protected override bool AllowDefaultResult => true;
|
||||
|
||||
public DownloadTask(string url, string filePath, TaskCompletionSource<NetworkResult<bool>> source, CancellationToken token) : base(url, source, token)
|
||||
{
|
||||
FilePath = filePath;
|
||||
}
|
||||
|
||||
protected override bool Completed(NSHttpUrlResponse? response)
|
||||
{
|
||||
if (Data == null)
|
||||
{
|
||||
throw new NullReferenceException("Data is null");
|
||||
}
|
||||
var result = Data.Save(FilePath, NSDataWritingOptions.Atomic, out NSError? error);
|
||||
if (error != null)
|
||||
{
|
||||
throw new Exception(error?.ToString() ?? "UUnknown error while saving file");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user