AppClip failed to download file with NSURLSessionDownloadTask

  • Hi,everyone. :)

  • Recently, I'm trying to make AppClip for my project. When I tried to use NSURLSessionDownloadTask[created by NSURLSession which is initialized with the config backgroundSessionConfigurationWithIdentifier] to download a file with a legal HTTPS URL. It's finally failed

  • 1)Environment:

    • MasOS BigSur

    • Xcode 12.2

    • Simulator [Run with automatic profile settings]

  • 2)Confusion:

    • The Main Target's download function is normal in the simulator with automatic profile settings.[Someone's advise, I just wanted to try]

  • 3)The Error Info:

    • Trigger Paths: Run AppClip->didFinishLaunchWithOptions->Initialize DownloadSessionTask->Task Resume.[UIApplicationState = UIApplicationStateActive]

    • callBack:URLSession:task:didCompleteWithError

    • below is lldb outputs:

Code Block JSON
2020-12-10 16:39:45.199333+0800 MFWAppClip[78965:2018825] BackgroundSession <73023646-DBBD-4BD9-B9EF-D79C9DB0B3AB> connection to background transfer daemon interrupted
2020-12-10 16:39:47.716800+0800 MFWAppClip[78965:2022242] Task <E6284F80-16C0-498B-A521-B3F9F67F1C92>.<1> finished with error [-1] Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo={NSErrorFailingURLStringKey=*****, NSErrorFailingURLKey=*******, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"BackgroundDownloadTask <E6284F80-16C0-498B-A521-B3F9F67F1C92>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundDownloadTask <E6284F80-16C0-498B-A521-B3F9F67F1C92>.<1>, NSLocalizedDescription=unknown error}
2020-12-10 16:39:51.123990+0800 MFWAppClip[78965:2018825] BackgroundSession <73023646-DBBD-4BD9-B9EF-D79C9DB0B3AB> an error occurred on the xpc connection to setup the background session: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.nsurlsessiond" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.nsurlsessiond}
  • Your opinions and suggestions would be greatly appreciated!~


  • Finally, I solved this problem by replacing the NSURLSessionConfiguration *bgconfig = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:self.bgSessionId]; with

  NSURLSessionConfiguration *bgconfig = [NSURLSessionConfiguration defaultSessionConfiguration];
  • It's clear that background session is not supported in the AppClip target. ~ :(

AppClip failed to download file with NSURLSessionDownloadTask
 
 
Q