Upload NSURLSesssion becomes invalidated in sharing extension in ios8 with error NSURLErrorDomain Code=-995

有些话、适合烂在心里 提交于 2019-12-09 05:27:53

问题


I try to upload an image using NSURLSession in shared extension in iOS 8 but have this error instantly after calling

[task resume]
Error Domain=NSURLErrorDomain Code=-995 "The operation couldn’t be completed. (NSURLErrorDomain error -995.)"

here is my code:

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:DEFAULT_SHARE_SESSION_ID];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:self.queue];
NSURLRequest *request = [self getMultipartUploadRequest:data url:url albumId:albumId];
// ... saving file here to Documents folder
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request fromFile:url1];
[uploadTask resume];

and also I have this message in console:

Attempted to create a task in a session that has been invalidated

This code absolutely works in the app, but doesn't work in the sharing extension. I couldn't find what does code -995 mean.

Any ideas?


回答1:


@Wisors great! It helped, just need to set

sessionConfiguration.sharedContainerIdentifier = @“com.me.myapp.containerIdentifier”;

In my case @“com.me.myapp.containerIdentifier” was @"group.mycompany.appname" which was crucial, another identifier didn't work. Thank you!



来源:https://stackoverflow.com/questions/26172783/upload-nsurlsesssion-becomes-invalidated-in-sharing-extension-in-ios8-with-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!