I am developing app using Xamarin.Forms and have an issue in Xamarin.iOS. Downloading pdf format file using NSUrlSession and shown progress in UI.
Code Snippet:
using (var sessionConfig = UIDevice.CurrentDevice.CheckSystemVersion(8, 0)
? NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration(Identifier)
: NSUrlSessionConfiguration.BackgroundSessionConfiguration(Identifier))
{
sessionConfig.NetworkServiceType = NSUrlRequestNetworkServiceType.Default;
this.session = NSUrlSession.FromConfiguration(sessionConfig, new UrlSessionDelegate(m_selectedEBook), NSOperationQueue.MainQueue);
}
ThreadPool.QueueUserWorkItem(async(object state) =>
{
using (var url = NSUrl.FromString(downloadURL.PdfDownloadUrl))
{
using (var request = NSUrlRequest.FromUrl(url))
{
downloadTask = session.CreateDownloadTask(request);
downloadTask.Resume();
}
}
}
Code to setup delegate and the delegate code itself (Get download progress using following NSUrlSessionDwonloadDelegate)
public class UrlSessionDelegate : NSUrlSessionDownloadDelegate, INSUrlSessionDelegate, INSUrlSessionTaskDelegate
{
public UrlSessionDelegate()
{
}
public override void DidFinishDownloading(NSUrlSession session, NSUrlSessionDownloadTask downloadTask, NSUrl location)
{
//Code to write progress in UI
}
public override void DidWriteData(NSUrlSession session, NSUrlSessionDownloadTask downloadTask, long bytesWritten, long totalBytesWritten, long totalBytesExpectedToWrite)
{
//Code to write progress in UI
}
}
It works fine but need to download three format file with single button click and also show progress of all format file download in a single progress control.
For this I have used CreateDownloadTaskAsync process as below,
await session.CreateDownloadTaskAsync(request, out downloadTask);
Note: Changed as CreateDownloadTaskAsync instead of CreateDownloadTask to achieve progress for multiple file download in single button click.
Following error comes in Xamarin.iOS,
Got a SIGSEGV while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.
The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
If removed CreateDownloadTaskAsync process, it works fine. Please help me to resolve this.