我想发送小帖子请求,但我不想每隔几分钟就发一次。有没有办法一次保存10个,一旦达到10个,那么它们都可以被发送?
某种队列?
以下是我构建请求的方式:
//Init request
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:url]];
//Set headers
[request setHTTPMethod:@"GET"];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
//get the http headers
NSHTTPURLResponse* newResp = (NSHTTPURLResponse*)response;
NSString *contentType = [newResp allHeaderFields][@"Content-Type"];
contentType = [contentType lowercaseString];
//serialize if content type is JSON
if ([WFHttp string:contentType contains:@"json"]) {
response = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
}
if (connectionError) {
NSLog(@"%@",connectionError);
}
//send completion
completion(response);
}];
答案 0 :(得分:1)
如果将请求存储在以用户默认值存储的数组中,并且每当您创建新请求时将其添加到该数组,该怎么办?一旦有10个请求,请将它们全部发送出去并清除用户默认值。