上传请求时出现NSException错误

时间:2017-06-10 07:26:20

标签: ios objective-c swift nsurlsession urlsession

我尝试使用后台模式上传视频,但我在uploadTask上获得libc++abi.dylib: terminating with uncaught exception of type NSException

fileprivate final class MultiPartHandler: NSObject {
    typealias SuccessHandler = ((Data?, URLResponse?, Error?) -> Void)

    var progressHandler: ProgressHandler
    var successHandler: SuccessHandler
    var errorHandler: ErrorHandler

    var uploadProgress: Progress
    var trackingQueue: DispatchQueue
    let sessionId: String
    let mediaData: Data
    let urlRequest: URLRequest

    required init(_ sessionId: String,_ queue: DispatchQueue,_ urlRequest: URLRequest,_ mediaData: Data,_ progress: @escaping ProgressHandler,_ success: @escaping SuccessHandler ,_ failure: @escaping ErrorHandler) {
        self.sessionId = sessionId
        self.trackingQueue = queue
        self.progressHandler = progress
        self.successHandler = success
        self.errorHandler = failure
        self.urlRequest = urlRequest
        self.mediaData = mediaData
        self.uploadProgress = Progress(totalUnitCount: 0)
        super.init()
    }

    func upload() {
        let config = URLSessionConfiguration.background(withIdentifier: "background_url_task")
        let session = URLSession(configuration: config, delegate: self, delegateQueue: OperationQueue())

        let uploadTask = session.uploadTask(with: urlRequest, from: mediaData, completionHandler: self.successHandler)
        uploadTask.resume()
    }
}

如果我将配置更改为URLSessionConfiguration.default工作正常,但它不适用于后台选项。

知道如何修复或调试它吗?

0 个答案:

没有答案