具有共享扩展名的NSURLSession在OSX上返回-995 [英] NSURLSession with share extension returns -995 on OSX

查看:77
本文介绍了具有共享扩展名的NSURLSession在OSX上返回-995的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NSURLSession以及OSX共享扩展中的后台任务上传数据.

I'm trying to upload data using NSURLSession with a background task from an OSX share extension.

我开始执行任务后,就会用世界上最没有帮助的错误消息来回呼委托人:

As soon as I start the task, by delegate is called back with the world's least helpful error message:

The operation couldn’t be completed. (NSURLErrorDomain error -995.)

NSError对象或控制台中没有其他信息.

There's no other information in the NSError object, nor in the console.

在浏览互联网之后,我唯一的线索就是确保正确设置了configuration.sharedContainerIdentifier,但是我已经做到了:

After scouring the internet, the only clue I have is to make sure that I've set up the configuration.sharedContainerIdentifier correctly, however I've already done that:

let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(uniqueId)
configuration.sharedContainerIdentifier = Config.appGroupName
urlSession = NSURLSession.init(configuration: configuration, delegate: self, delegateQueue: nil)

然后我准备请求并创建任务:

I then prepare the request and create the task:

let task = self.urlSession!.dataTaskWithRequest(request)
self.tasks.append(task)
task.resume()

请注意,从我的主应用程序运行时,一切正常.仅仅是共享扩展失败了.

Note that everything works perfectly when from my main app. It's just the sharing extension that fails.

还有哪些其他问题可能导致错误-995?

What other problems could cause error -995?

推荐答案

(和我一起,我还没有代表要发表评论,所以我必须回答,尽管您可能找到了错误,我要添加的最后一部分可能会对其他人有所帮助)

当您使用NSURLSession时,完成的任何后台上传/下载都将启动您的主应用程序.这在常见情况页面.

When you're using an NSURLSession any background upload/download that completes will launch your main application. This is detailed in the Common Scenarios page.

如已完成,您需要将NSURLSessionConfiguration设置为sharedContainerIdentifier:

As you show you've done, you need to set the NSURLSessionConfiguration with a sharedContainerIdentifier:

let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(uniqueId)
configuration.sharedContainerIdentifier = Config.appGroupName
urlSession = NSURLSession.init(configuration: configuration, delegate: self, delegateQueue: nil)

您还需要确保在Xcode的应用组"选项中(我正在查看Xcode 8.1)对您的应用扩展程序和主应用程序都进行了三重检查,这意味着:

You also need to ensure that both your app extension and your main app are all triple-checked in the 'App Groups' option in Xcode (I'm looking at Xcode 8.1), which means:

  • 应用组名称和扩展名都相同()
  • Add the App Group entitlements in the entitlement file
  • 旁边的支票
  • Add the App Groups feature to your App ID
  • 旁边的支票
  • Add App Groups to your App ID
  • 旁边的支票
  • The app group name is the same for both app and extension(!)
  • the check beside Add the App Group entitlements in the entitlement file
  • the check beside Add the App Groups feature to your App ID
  • the check beside Add App Groups to your App ID

并且需要在 应用和扩展程序上进行检查.

And the checks need to be there on both app and extension.

我对添加这些内容有些不满意,但我的回忆是这些对象的排列顺序不正确,例如您必须先将应用程序组添加到您的ID",然后才能在应用程序和扩展程序中进行检查,但我可能是错的.

I'm a bit rusty on adding these but my recollection is these aren't listed in the right order, e.g. you have to 'Add App Groups to your ID' before you can check them in both app and extension, but I could be wrong.

高级-应用扩展中的第三方库.

Advanced - Thirdparty libraries in app extensions.

查看第三方Twitter REST库github项目nst/STTwitter,他们需要添加可配置的组ID,以允许将NSURLSessionConfiguration sharedContainerIdentifier设置为库用户的组ID.

Looking at the github project nst/STTwitter, a third-party Twitter REST library, they needed to add a configurable group ID to allow setting the NSURLSessionConfiguration sharedContainerIdentifier to the library user's group ID.

我可能再次被误认为,但是在应用扩展中使用第三方库时,这似乎是一个普遍的问题-例如我刚刚在尝试使用ChromeCast SDK时遇到了此错误,这可能是小问题.

I may again be mistaken but this seems like it would be a general problem when using thirdparty libraries in an app extension - e.g. I've just now come across this error when trying to use the ChromeCast SDK and this could be the kick in the pants.

这篇关于具有共享扩展名的NSURLSession在OSX上返回-995的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆