AFNetworking Background Session Configuration for iOS 8 Extension

Deadly 提交于 2019-12-03 07:28:13

From the docs:

If your app extension initiates a background NSURLSession task, you must also set up a shared container that both the extension and its containing app can access. Use the sharedContainerIdentifier property of the NSURLSessionConfiguration class to specify an identifier for the shared container so that you can access it later.

And:

If you attempt to use create a URL session from your app extension but fail to set this property to a valid value, the URL session is invalidated upon creation.

Refer to Sharing Data with Your Containing App for guidance on setting up a shared container.

In your example, you'd add something like:

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

You'll need one background session for the containing app and one for its extension.

Make sure your sharedContainerIdentifier is the same identifier as the group identifier you registered for both your host app and extension app.

config.sharedContainerIdentifier = @“com.mycompany.myappgroupidentifier”;

You can register a group identifier in Xcode capabilities project tab.

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