- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
照片应用如何在后台上传 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];
}
}
}
最佳答案
任务不简单,有很多工作要做。
从 [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:] 和 +[NSURLSession uploadTaskWith...] 方法开始。
您会发现棘手的部分是从上传错误中恢复。您需要通过检查 -[NSURLSession getTasksWithCompletionHandler:] 来跟踪应用程序中的每个后台上传。但首先要从头开始,包括后台 session 配置和上传任务。
关于ios8:如何使用 NSURLSession 在后台上传 100 多张照片?可用空间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29160936/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!