SIGABRT:后台会话不支持从NSData上传任务

时间:2017-03-26 18:54:28

标签: ios swift alamofire nsurlsession alamofireimage

我正在使用Alamofire进行上传。我需要将多个图像和视频上传到我的服务器。我需要将图像和视频上传到后台会话中甚至

    let bundleIdentifier = Bundle.main.bundleIdentifier
            let configuration = URLSessionConfiguration.background(withIdentifier: bundleIdentifier!)
            configuration.timeoutIntervalForRequest = 200 // seconds
            configuration.timeoutIntervalForResource = 200
            self.alamoFireManager = Alamofire.SessionManager(configuration: configuration)

I am using above code setup alamofire for background configuration.
            alamoFireManager?.upload(data!, with: (router))
                .uploadProgress { progress in // main queue by default
                    print("Upload Progress: \(progress.fractionCompleted)")
                }.validate()
                .responseJSON { [weak self] response in
}

但是当我使用SIGABRT

进入后台时,我的应用程序崩溃了

让我知道我做错了什么,

1 个答案:

答案 0 :(得分:0)

这是Apple的NSUrlSession实施的限制。 Apple不允许将NSData用于后台会话。但允许上传文件。因此,作为一种解决方法,您可以尝试将数据写入文件并上传该文件。您可以按照此处的实施进行操作:

https://stackoverflow.com/a/22107789/1921759