AFJSONRequestOperation を使用する関数があり、成功した場合にのみ結果を返したいと考えています。正しい方向に私を向けることができますか?特にブロックと AFNetworking については、まだ少し無知です。
質問する
41 次
1 に答える
0
コードを投稿しておけばよかった
使用__block
すると、ブロック内で変数を使用できます
__block NSString *msg;
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[hud hide:YES];
NSLog(@"Success %@", operation.responseString);
NSDictionary *message = [NSJSONSerialization JSONObjectWithData:[operation.responseString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@",message);
msg = message
ALERT(@"Posted", message[@"message"]);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", operation.responseString);
NSLog(@"%@",error);
}];
[operation start];
于 2013-11-15T07:44:47.217 に答える