私はAFNetworkingを使用しており、jsonのフィードバックが必要なポストリクエストを作成しています。以下のコードは動作しますが、私は2つの主な質問があります。 ActivityIndicator Managerのリリースはどこですか? 2番目の質問はこのコードが正しいことです。新しいものです。ブロックと混同されるので、うまく動作しているかどうかを知りたいのです。AFNetworkingポストリクエストwith json feedback
NSURL *url = [NSURL URLWithString:@"mysite/user/signup"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
AFNetworkActivityIndicatorManager * newactivity = [[AFNetworkActivityIndicatorManager alloc] init];
newactivity.enabled = YES;
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
usernamestring, @"login[username]",
emailstring, @"login[email]",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"mysite/user/signup"parameters:params];
[httpClient release];
AFJSONRequestOperation *operation = [AFJSONRequestOperation operationWithRequest:request success:^(id json) {
NSString *status = [json valueForKey:@"status"];
if ([status isEqualToString:@"success"]) {
[username resignFirstResponder];
[email resignFirstResponder];
[self.navigationController dismissModalViewControllerAnimated:NO];
}
else {
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Login Unsuccessful"
message:@"Please try again"
delegate:NULL
cancelButtonTitle:@"OK"
otherButtonTitles:NULL];
[alert show];
[alert release];
}
}
failure:^(NSHTTPURLResponse *response, NSError *error) {
NSLog(@"%@", error);
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Login Unsuccessful"
message:@"There was a problem connecting to the network!"
delegate:NULL
cancelButtonTitle:@"OK"
otherButtonTitles:NULL];
[alert show];
[alert release];
}];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
NSLog(@"check");
}
は、事前にあなたの助けをありがとうございました:)
どこ 'AFJSONRequestOperation operationWithRequest:成功事例の:仕上げ:'メソッドから来る? APIでは表示されません。 –
@reakinator彼は実際に '+ JSONRequestOperationWithRequest:success:failure:'を参照してください。[ここ](https://github.com/AFNetworking/AFNetworking#readme)を参照してください。 – borisdiakur