Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLSession from macos Sharing Extension

I'm getting this error in the func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) { URLSessionDataDelegate method:

error=Optional(Error Domain=NSURLErrorDomain Code=-1 “unknown error” UserInfo={NSErrorFailingURLKey=https://www.example.com/, NSLocalizedDescription=unknown error, NSErrorFailingURLStringKey=https://www.example.com/})

Very similar code works perfectly from an application, but I'm trying to write an Sharing App Extension which uploads to a webserver.

I'm using URLSessionConfiguration.background(withIdentifier:"...") same as my desktop application.

Why do I get erorr -1?

like image 862
jrwren Avatar asked Aug 18 '26 14:08

jrwren


1 Answers

I was missing the com.apple.security.network.client entitlement in the entitlements file.

https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW9

like image 123
jrwren Avatar answered Aug 22 '26 03:08

jrwren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!