目前我正在开展一个项目,我们需要将一组照片和视频发送到S3亚马逊服务器.流程是这样的:
- 首先我们要求api开始转移,我们得到一个id(api call)
-transfer id - >请求文件上传到api - > file_id作为响应(api调用)
-file id - >在api请求块上传 - > amazon数据作为响应(api调用)
-upload chunck - >在backgroundConfiguration中配置的NSURLSession中(每次上传5mb)
上次chunck-upload(api调用)后上传文件
上次文件上传后的最终转移(api通话)
我们需要使用api并对其进行调用..当应用程序在后台运行时也是如此.
所以我想的是使用可以在后台上传文件然后运行完成块的AFNetworking 2.0.
在完成块中,代码如下:
_managerBackground = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
- (void)uploadChunkInTheBackGround:(RequestChunkUploadResponse *)requestChunkUploadResponse
{
UploadChunkRequest *chunkUploadRequest = [[UploadChunkRequest alloc]initWithRequestChunkUploadResponse:requestChunkUploadResponse];
APIService *weakSelf = (APIService *)self;
NSURLSessionUploadTask *uploadTask = [_managerBackground uploadTaskWithRequest:chunkUploadRequest.request fromFile:chunkUploadRequest.fileLocationURL progress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
//code to prepare recursive upload and files
[weakSelf uploadChunkInTheBackGround:chunkUploadResponse];
}];
Run Code Online (Sandbox Code Playgroud)
所以困难在于我们喜欢执行代码并尝试在iOS7的后台执行上传任务
当应用程序连接到调试器(Xcode)时,上面的示例工作.但没有它在控制台中提供此错误:
<BKProcessAssertion: 0x178468380> identifier: com.apple.nsnetworkd.handlesession process: YourApp[675] permittedBackgroundDuration: …
Run Code Online (Sandbox Code Playgroud) 我用api向我提供网上的数据.数据采用Json格式,并存储在NSDictionary
.像这样:
SBJSON *parser = [[SBJSON alloc] init];
dict = [[NSDictionary alloc]init];
dict = [parser objectWithString:jsonArray error:nil];
Run Code Online (Sandbox Code Playgroud)
Ggb控制台结果:po dict
1262 = {
"feed_name" = name1;
"new_results" = 6;
"next_update" = "2010-02-16T15:22:11+01:00";
};
1993 = {
"feed_name" = name2;
"new_results" = 0;
"next_update" = "2010-02-16T09:09:00+01:00";
};
Run Code Online (Sandbox Code Playgroud)
我如何访问值"1262"和"1993"并将它们放入一个NSArray
,用于aUITableView
非常感谢,问候,巴特