私はたくさん検索していくつかの答えを見ましたが、それを解決する方法はまだわかりません.操作が完了したときにのみ、void関数を実行したい.
私のコード:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPBody:[soapBody dataUsingEncoding:NSUTF8StringEncoding]];
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request addValue:kAPP_PASSWORD_VALUE forHTTPHeaderField:kAPP_PASSWORD_HEADER];
[request addValue:@"http://blablabla" forHTTPHeaderField:@"SOAPAction"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.responseXML = [operation responseString];
NSData *data = [self.responseXML dataUsingEncoding:NSUTF8StringEncoding];
[self doParse:data];
self.numOfWallPosts = [self.sharedPrefs integerForKey:@"total_number_of_wall_posts"];
for (int i = 1; i <= self.numOfWallPosts; i++)
{
NSString *sharedKey = [NSString stringWithFormat:@"wall_number_%d", i];
NSMutableDictionary *aaa = [[NSMutableDictionary alloc] init];
aaa = [self.sharedPrefs objectForKey:sharedKey];
[self handleWallPostsWithWallPost:aaa];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"\n\nError: %@", error);
}];
[operation start];
[self handleWallPostsWithWallPost:aaa];
- バックグラウンドでいくつかの画像をダウンロードしているため、ブロックは完了していますが、バックグラウンドでいくつかの画像がダウンロードされています。画像のダウンロードがいつ完了したかを知るにはどうすればよいですか?
- (void)handleWallPostsWithWallPost:(NSMutableDictionary *)wallPost
{
NSMutableDictionary *temp = [[NSMutableDictionary alloc] init];
temp = wallPost;
NSString *owner = [temp objectForKey:@"owner"];
NSString *title = [temp objectForKey:@"title"];
NSString *imageUrl = [temp objectForKey:@"image_url"];
NSInteger wallId = [[temp objectForKey:@"wall_id"] integerValue];
NSLog(@"Wall ID: %d | Owner: %@ | Title: %@ | Image URL: %@", wallId, owner, title, imageUrl);
// arrayOfOwnersImage - Save as NSData
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:imageUrl]];
AFImageRequestOperation *operation;
operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessingBlock:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
NSLog(@"Image downloaded...");
NSData *imageData = UIImageJPEGRepresentation(image, 90);
[self.arrayOfOwnersImage addObject:imageData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Image download fail: %@", [error localizedDescription]);
}];
[operation start];
}
何か案は?