1
我嘗試實現用戶可以在App.net上共享圖像的擴展。在共享擴展中上傳圖像導致NSURLErrorDomain代碼= -997
經過大量的試驗和錯誤,我終於出來了想法。
我有一個框架來創建請求。該請求是POST請求Content-Disposition: form-data
。因此我認爲我必須使用sessionDataTask
來上傳圖片。
會話的委託是同一個框架中的單例。一些委託方法被調用。
但是didReceiveData
永遠不會被調用。在代替我收到以下錯誤didCompleteWithError
任何上傳開始前:
Error Domain=NSURLErrorDomain Code=-997 "Lost connection to background transfer service" UserInfo=0x7b29dc80 {NSErrorFailingURLKey=https://alpha-api.app.net/stream/0/files, NSErrorFailingURLStringKey=https://alpha-api.app.net/stream/0/files, NSLocalizedDescription=Lost connection to background transfer service}
這裏是份額擴展代碼:
let imageUploadRequest = RequestFactory.imageUploadRequest(imageToShare, accessToken: accessToken!)
let sessionId = "de.dasdom.jupp.image.backgroundsession"
let config = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(sessionId)
config.sharedContainerIdentifier = "group.de.dasdom.Jupp"
let session = NSURLSession(configuration: config, delegate: PostService.sharedService, delegateQueue: NSOperationQueue.mainQueue())
let sessionTask = session.dataTaskWithRequest(imageUploadRequest)
sessionTask.resume()
self.extensionContext!.completeRequestReturningItems(nil, completionHandler: nil)
這也使在主機應用程序相同的錯誤。
我已經在共享擴展和主機應用程序中設置了一個應用程序組。
上傳確實有效,但我需要上傳的響應才能撰寫App.net的文章。當我使用正常的NSURLSession時,一切正常。
任何幫助將不勝感激。
謝謝。可能。但是,我會考慮一個錯誤,因爲這是後臺任務的工作。我已經嘗試了一個上傳任務,但API似乎不能使用它。 – dasdom 2014-12-12 21:04:52