照片应用程序如何在后台从 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];
}
}
}