我锁定设备屏幕时数据上传停止

时间:2016-11-09 13:25:33

标签: ios objective-c

我正在使用AFNetworking在服务器上上传视频文件它在后台模式下正常工作,当应用程序在前台时,但当我锁定屏幕时,它停止上传并且不会给出任何错误并转到compltion处理程序。 这是代码

 AFURLConnectionOperation *operation =   [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSUInteger __unused bytesWritten,
                                    long long totalBytesWritten,
                                    long long totalBytesExpectedToWrite) {
    NSLog(@"Wrote Data %lld/%lld", totalBytesWritten, totalBytesExpectedToWrite);
    [self setProgress:(float)totalBytesWritten/(float)totalBytesExpectedToWrite];
}];

typeof(operation) __weak weakOperation = operation;
[operation setCompletionBlock:^{
    if([weakOperation isFinished]) {  
        [SVProgressHUD showSuccessWithStatus:DISCUSSION_SAVE_SUCCESS];
    } else {
        [SVProgressHUD showErrorWithStatus:ERROR];

    }
}];

[operation start];

1 个答案:

答案 0 :(得分:0)

使用-[NSURLSessiont uploadTaskWithRequest:...]方法