【问题标题】:Data Uploading stop when i locked the screen of device当我锁定设备的屏幕时,数据上传停止
【发布时间】:2016-11-09 13:25:33
【问题描述】:

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

 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];

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-02-12
      • 1970-01-01
      • 2017-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多