我试图在应用程序处于后台时将文件上传到我的服务器, 我的NSOperation设置如下:
class uploadOperation: NSOperation {
weak var request: Alamofire.Request?
override func main() {
let task = backgroundTaskManager.sharedManager.backgroundTask
request = task.upload(.POST, "http://foo.com", headers: nil, file: fileURL).responseJSON { response in
}
}
override func cancel() {
request?.cancel()
super.cancel()
}
}
我设置了后台会话配置。
class backgroundTaskManager: NSObject {
class var sharedManager:backgroundTaskManager {
struct Static {
static let instance:backgroundTaskManager = backgroundTaskManager()
}
return Static.instance
}
lazy var backgroundTask: Alamofire.Manager = {
let identifier = "com.MyAppName.background"
return Alamofire.Manager(configuration: NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(identifier))
}()
}
func application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -> Void) {
backgroundTaskManager.sharedManager.backgroundTask.backgroundCompletionHandler = completionHandler
}
*我正在使用Alamofire 3.2.1 *
当我去后台应用程序上传1个文件然后停止,我做错了什么?