gpt4 book ai didi

ios8:如何使用 NSURLSession 在后台上传 100 多张照片?可用空间问题

转载 作者:可可西里 更新时间:2023-11-01 05:52:34 25 4
gpt4 key购买 nike

照片应用如何在后台上传 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com