Repository navigation
Description
Steps to Reproduce
I tried to download 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();
}
}
}
Get download progress using following NSUrlSessionDwonloadDelegate:
Code to setup delegate and the delegate code itself:
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);
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.
Expected Behavior
Actual Behavior
Environment
=== Visual Studio Community 2017 for Mac ===
Version 7.2.2 (build 7)
Installation UUID: bb05f286-5b1f-48ab-b0d5-bc61d62b54cb
Runtime:
Mono 5.4.1.6 (2017-06/1f4613aa1ac) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Package version: 504010006
=== NuGet ===
Version: 4.3.1.4445
=== .NET Core ===
Runtime: Not installed
SDK: Not installed
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks
=== Xamarin.Profiler ===
Version: 1.5.6
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Xamarin.Android ===
Not Installed
=== Xamarin Inspector ===
Not Installed
=== Apple Developer Tools ===
Xcode 8.3.2 (12175)
Build 8E2002
=== Xamarin.iOS ===
Version: 11.2.0.11 (Visual Studio Community)
Hash: 2f8bbec
Branch: d15-4-xi
Build date: 2017-10-05 20:56:05-0400
=== Xamarin.Mac ===
Version: 3.8.1.0 (Visual Studio Community)
=== Build Information ===
Release ID: 702020007
Git revision: 2236098c68f51eeb447cb947a87371d1e84f6213
Build date: 2017-10-23 11:43:05-04
Xamarin addins: eaa605cf97f25ce184949f32c712b465ca96f665
Build lane: monodevelop-lion-d15-4
=== Operating System ===
Mac OS X 10.12.4
Darwin 16.5.0 Darwin Kernel Version 16.5.0
Fri Mar 3 16:52:33 PST 2017
root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Activity
spouliot commentedon Feb 6, 2018
^ it looks like you're trying to access a non secure resource, e.g.
http://, and have not editing forInfo.plistto allow this.Apple started to disallow this, by default, a few years back. Try this with an
https://URL to see if it solves your issue.Cheranarasu commentedon Feb 8, 2018
Hi @spouliot ,
I tried to download
https://URL only. Download properly works withCreateDownloadTaskand had problem when useCreateDownloadTaskAsynconly. I need to use async to achieve my scenario. Need to download three format file with single button click.Regards,
Cheran
spouliot commentedon Feb 8, 2018
That's weird because you should not be seeing the message you pasted.
Anyway the best way to solve this is to attach a self-contained test case to this issue so we're able to duplicate the same crash (just by running the test case and see if crash). There's a lot of moving pieces in networking code and duplicating results can often be hard (timing, servers, protocols...).
Cheranarasu commentedon Feb 8, 2018
Hi @spouliot ,
Sorry for inconvenience.
I tried to download
http://only, it download properly ifCreateDownloadTaskused and error occurs only if useCreateDownloadTaskAsyncprocess. I have used below link process for App Transport Security policy,https://stackoverflow.com/questions/32631184/the-resource-could-not-be-loaded-because-the-app-transport-security-policy-requi
Please find sample Xamarin iOS project with single download which using both
CreateDownloadTaskandCreateDownloadTaskAsync. Initially,CreateDownloadTaskAsynccomment and download code placed in SimpleBackgroundTransferViewController.cs file.http://files2.syncfusion.com/Downloads/BackgroundSample.zip
Please check it and give your valuable suggestion.
Cheranarasu commentedon Feb 12, 2018
Hi @spouliot ,
I am struck on this for a week. Please give your valuable suggestion on this.
Regards,
Cheran
Cheranarasu commentedon Feb 14, 2018
Hi @spouliot ,
Is this Xamarin issue or not?. Please suggest any workaround for this if it is Xamarin issue or give any other suggestion to implement my process . I have already attached sample source in previous conversation itself. Please help me on this.
Regards,
Cheran
spouliot commentedon Feb 14, 2018
@mandel-macaque can you please have a look at the attached sample ? thanks!
Cheranarasu commentedon Feb 19, 2018
Hi @spouliot / @mandel-macaque ,
Could you please update any on this?
Regards,
Cheran
mandel-macaque commentedon Feb 20, 2018
@Cheranarasu looking at the issue, will get back to you with more information ASAP.
mandel-macaque commentedon Feb 20, 2018
I have taken a look at the issue and the problem is not related to Xamarin but on how you are using the API. I have modified a little your code here to get you application to run and download several images asynchronously using the OS because you wanted to use a background session. The tasks are started in the background when Resume is called:
So there is no need to use a ThredPool, await or any of the .net constructs. Something similar can be achieved with the Async methods, but those will be controlled by the app and will not use a background session.
Cheranarasu commentedon Feb 21, 2018
Thanks for your update. I thought you may misunderstood my concept. I have to download three file in a single click with background process too and maintain a three file download progress into single progress bar (Put calculation to progress by receiving byte divided by total byte of three file). If we do like above, download couldn't wait for another and also one file completed then download completed event triggers. Because of this only, try to use
CreateDownloadTaskAsyncand await to wait once download is going it stays and once download completed then triggers another download.I have achieved this by
DownloadFileTaskAsyncprocess usingWebClient. When unclock iOS device or minimize application download doesn't carry out. To achieve this only came forNSURLSession, if useCreateDownloadTaskAsyncthen application stopped. I have pasted console output in it.WebClient Code Snippet:
Also three file downloaded source updated in it. Please find source below and check it.
http://files2.syncfusion.com/Downloads/BackgroundSample1.zip
2018-02-21 14:27:10.905 SimpleBackgroundTransfer[323:47059] Xamarin.iOS: IDE Port: 10000 Transport: USB
Launched application 'com.syncfusion.BackgroundSession' on 'Syncpad-14473' with pid 323
2018-02-21 14:27:10.981 SimpleBackgroundTransfer[323:47059] Xamarin.iOS: Successfully received USB connection from the IDE on port 10000, fd: 4
2018-02-21 14:27:10.982 SimpleBackgroundTransfer[323:47059] Xamarin.iOS: Processing: 'start debugger: sdb'
2018-02-21 14:27:10.983 SimpleBackgroundTransfer[323:47040] Xamarin.iOS: Debugger loaded with custom transport (fd: 4)
2018-02-21 14:27:10.983 SimpleBackgroundTransfer[323:47059] Xamarin.iOS: Successfully received USB connection from the IDE on port 10000, fd: 5
2018-02-21 14:27:10.983 SimpleBackgroundTransfer[323:47059] Xamarin.iOS: Processing: 'connect output'
2018-02-21 14:27:10.984 SimpleBackgroundTransfer[323:47059] Xamarin.iOS: Successfully received USB connection from the IDE on port 10000, fd: 6
2018-02-21 14:27:10.984 SimpleBackgroundTransfer[323:47059] Xamarin.iOS: Processing: 'start profiler: no'
2018-02-21 14:27:10.985 SimpleBackgroundTransfer[323:47040] Xamarin.iOS: Profiler not loaded (disabled)
Loaded assembly: /private/var/containers/Bundle/Application/B02E5BCB-2E0D-495E-9B49-29163E76A151/SimpleBackgroundTransfer.app/Xamarin.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/B02E5BCB-2E0D-495E-9B49-29163E76A151/SimpleBackgroundTransfer.app/System.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/B02E5BCB-2E0D-495E-9B49-29163E76A151/SimpleBackgroundTransfer.app/SimpleBackgroundTransfer.exe
Thread started: #2
2018-02-21 14:27:11.354 SimpleBackgroundTransfer[323:47040] OnActivated
2018-02-21 14:27:11.374 SimpleBackgroundTransfer[323:47040] InitBackgroundSession
Resolved pending breakpoint at 'SimpleBackgroundTransferViewController.cs:209,1' to void SimpleBackgroundTransfer.UrlSessionDelegate.DidFinishEventsForBackgroundSession (Foundation.NSUrlSession session) [0x00001].
Thread started: #3
Thread started: #4
Thread started: #5
Thread started: #6
Resolved pending breakpoint at 'SimpleBackgroundTransferViewController.cs:79,1' to void SimpleBackgroundTransfer.SimpleBackgroundTransferViewController.<b__8_1>d.MoveNext () [0x00028].
2018-02-21 14:27:21.674 SimpleBackgroundTransfer[323:47098] error: Assertion at /Users/builder/data/lanes/5481/2f8bbec0/source/xamarin-macios/external/mono/mono/mini/debugger-agent.c:4714, condition `array->len == 1' not met
2018-02-21 14:27:21.675 SimpleBackgroundTransfer[323:47098] critical: Stacktrace:
2018-02-21 14:27:21.676 SimpleBackgroundTransfer[323:47098] critical:
Native stacktrace:
2018-02-21 14:27:21.681 SimpleBackgroundTransfer[323:47098] critical: 0 SimpleBackgroundTransfer 0x00000001001fa5b4 SimpleBackgroundTransfer + 2074036
2018-02-21 14:27:21.682 SimpleBackgroundTransfer[323:47098] critical: 1 libsystem_platform.dylib 0x000000018a16d348 _sigtramp + 52
2018-02-21 14:27:21.682 SimpleBackgroundTransfer[323:47098] critical: 2 libsystem_pthread.dylib 0x000000018a173450 pthread_kill + 112
2018-02-21 14:27:21.683 SimpleBackgroundTransfer[323:47098] critical: 3 libsystem_c.dylib 0x000000018a01f400 abort + 140
2018-02-21 14:27:21.683 SimpleBackgroundTransfer[323:47098] critical: 4 SimpleBackgroundTransfer 0x00000001002ed984 xamarin_get_block_descriptor + 7716
2018-02-21 14:27:21.684 SimpleBackgroundTransfer[323:47098] critical: 5 SimpleBackgroundTransfer 0x00000001002e7924 mono_pmip + 937176
2018-02-21 14:27:21.686 SimpleBackgroundTransfer[323:47098] critical: 6 SimpleBackgroundTransfer 0x00000001002e7b1c mono_pmip + 937680
2018-02-21 14:27:21.686 SimpleBackgroundTransfer[323:47098] critical: 7 SimpleBackgroundTransfer 0x00000001001e5ee8 SimpleBackgroundTransfer + 1990376
2018-02-21 14:27:21.687 SimpleBackgroundTransfer[323:47098] critical: 8 SimpleBackgroundTransfer 0x00000001001db23c SimpleBackgroundTransfer + 1946172
2018-02-21 14:27:21.687 SimpleBackgroundTransfer[323:47098] critical: 9 SimpleBackgroundTransfer 0x00000001001dae6c SimpleBackgroundTransfer + 1945196
2018-02-21 14:27:21.687 SimpleBackgroundTransfer[323:47098] critical: 10 SimpleBackgroundTransfer 0x00000001001423dc SimpleBackgroundTransfer + 1319900
2018-02-21 14:27:21.688 SimpleBackgroundTransfer[323:47098] critical: 11 SimpleBackgroundTransfer 0x000000010000e20c SimpleBackgroundTransfer + 57868
2018-02-21 14:27:21.689 SimpleBackgroundTransfer[323:47098] critical: 12 SimpleBackgroundTransfer 0x00000001000d006c SimpleBackgroundTransfer + 852076
2018-02-21 14:27:21.689 SimpleBackgroundTransfer[323:47098] critical: 13 SimpleBackgroundTransfer 0x000000010000bd20 SimpleBackgroundTransfer + 48416
2018-02-21 14:27:21.690 SimpleBackgroundTransfer[323:47098] critical: 14 SimpleBackgroundTransfer 0x00000001000be294 SimpleBackgroundTransfer + 778900
2018-02-21 14:27:21.690 SimpleBackgroundTransfer[323:47098] critical: 15 SimpleBackgroundTransfer 0x00000001000b7e74 SimpleBackgroundTransfer + 753268
2018-02-21 14:27:21.691 SimpleBackgroundTransfer[323:47098] critical: 16 SimpleBackgroundTransfer 0x00000001000b7ccc SimpleBackgroundTransfer + 752844
2018-02-21 14:27:21.691 SimpleBackgroundTransfer[323:47098] critical: 17 SimpleBackgroundTransfer 0x00000001000be1fc SimpleBackgroundTransfer + 778748
2018-02-21 14:27:21.692 SimpleBackgroundTransfer[323:47098] critical: 18 SimpleBackgroundTransfer 0x00000001000bc45c SimpleBackgroundTransfer + 771164
2018-02-21 14:27:21.692 SimpleBackgroundTransfer[323:47098] critical: 19 SimpleBackgroundTransfer 0x0000000100180d40 SimpleBackgroundTransfer + 1576256
2018-02-21 14:27:21.693 SimpleBackgroundTransfer[323:47098] critical: 20 SimpleBackgroundTransfer 0x00000001000be008 SimpleBackgroundTransfer + 778248
2018-02-21 14:27:21.693 SimpleBackgroundTransfer[323:47098] critical: 21 SimpleBackgroundTransfer 0x0000000100127074 SimpleBackgroundTransfer + 1208436
2018-02-21 14:27:21.693 SimpleBackgroundTransfer[323:47098] critical: 22 SimpleBackgroundTransfer 0x0000000100207bb4 mono_pmip + 20328
2018-02-21 14:27:21.694 SimpleBackgroundTransfer[323:47098] critical: 23 SimpleBackgroundTransfer 0x00000001002684c0 mono_pmip + 415860
2018-02-21 14:27:21.695 SimpleBackgroundTransfer[323:47098] critical: 24 SimpleBackgroundTransfer 0x0000000100284528 mono_pmip + 530652
2018-02-21 14:27:21.695 SimpleBackgroundTransfer[323:47098] critical: 25 SimpleBackgroundTransfer 0x0000000100282a54 mono_pmip + 523784
2018-02-21 14:27:21.696 SimpleBackgroundTransfer[323:47098] critical: 26 SimpleBackgroundTransfer 0x0000000100289db4 mono_pmip + 553320
2018-02-21 14:27:21.696 SimpleBackgroundTransfer[323:47098] critical: 27 libsystem_pthread.dylib 0x000000018a171850 + 240
2018-02-21 14:27:21.696 SimpleBackgroundTransfer[323:47098] critical: 28 libsystem_pthread.dylib 0x000000018a171760 + 0
2018-02-21 14:27:21.697 SimpleBackgroundTransfer[323:47098] critical: 29 libsystem_pthread.dylib 0x000000018a16ed94 thread_start + 4
2018-02-21 14:27:21.698 SimpleBackgroundTransfer[323:47098] critical:
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Please let me know if further details needed.
Regards,
Cheran
Cheranarasu commentedon Feb 26, 2018
Hi @mandel-macaque ,
I have updated comment on this. Could you please reopen this issue and check it?. Please ping sample for
CreateDownloadTaskAsyncprocess and this will help me to process in my scenario.Regards,
Cheran
mandel-macaque commentedon Feb 27, 2018
@Cheranarasu I am not reopening the bug because there is no issue in the platform. The problem you have is that you are not an expert with the API and due to that you are getting a crash. This is not the right channel to request help with this kind of issues, I recommend the following:
Nevertheless, here you have a sample code that will do the following:
The requests are done in parallel and the progress bar will be updated correctly. If you want to perform the downloads one after the other, you have to add logic so that,
Again, please do not use github issues to request support when you have issues understanding the API and use the forums or stack overflow for that kind of questions, this channel is just for bug reports which is not this case.
LeeCenY commentedon Nov 16, 2018
I also have this problem, also download PDF files.
I used the SDK of other companies that bind the Objective-C API. This problem caused the program to crash in the download PDF method, but the development on xcode native did not crash.
bind the Objective-C API
call bind the Objective-C API
Crash output
Environment