【发布时间】:2015-03-20 06:48:00
【问题描述】:
照片应用如何在后台从 CameraRoll 上传所有内容?
我需要根据日期范围在后台上传 100 张照片。我的应用程序当前正在使用NSURLSession 和以下代码(我认为......)但为了使其工作,我的任务计划程序必须在应用程序运行之前将 JPG 复制到应用程序存储中的文件(请参阅:Background Upload With Stream Request Using NSUrlSession in iOS8)进入背景。对于 100 多张照片,这需要太多时间和存储空间。
有没有办法使用“流”方法,或者从后台可靠地安排额外的NSURLSession 任务?我的开发人员说,可能在 iCloud 中的 CameraRoll 照片会导致后台调度失败。
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
didSendBodyData:(int64_t)bytesSent
totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
NSString *identifier = task.originalRequest.allHTTPHeaderFields[@"X-Image-Identifier"];
NSDictionary *d = [self sessionInfosDictionary];
NSURLSessionTaskInfo *info = d[identifier];
double p = (double)totalBytesSent/(double)totalBytesExpectedToSend;
info.progress = p;
[self saveSessionInfos:d];
for (id<PhotosUploaderDelegate>delegate in _delegates) {
if ([delegate respondsToSelector:@selector(photoUploader:didUploadDataForAssetWithIdentifier:totalBytesSent:totalBytesExpectedToSend:)]) {
[delegate photoUploader:self didUploadDataForAssetWithIdentifier:identifier totalBytesSent:totalBytesSent totalBytesExpectedToSend:totalBytesExpectedToSend];
}
}
}
【问题讨论】:
标签: ios ios8 nsurlsession nsurlsessionuploadtask