मैं AFNetworking का उपयोग कर रहा हूं और एक पोस्ट अनुरोध तैयार कर रहा हूं जिसके लिए मुझे जेसन प्रतिक्रिया की आवश्यकता है। नीचे दिया गया कोड काम करता है हालांकि मेरे पास दो मुख्य प्रश्न हैं; मैं गतिविधिइंडिकेटर प्रबंधक कहां से जारी करूं? दूसरा सवाल यह कोड सही है, नया होने के कारण मैं ब्लॉक के साथ भ्रमित हो जाता हूं, इसलिए मैं वास्तव में जानना चाहता हूं कि मैं इसे सही प्रदर्शन के लिए सही काम कर रहा हूं, भले ही यह काम करता हो।जेसन प्रतिक्रिया के साथ AFNetworking पोस्ट अनुरोध
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: सफलता: खत्म:' विधि से आते हैं? मैं इसे एपीआई में नहीं देखता हूं। –
@reakinator वह वास्तव में '+ JSONRequestOperationWithRequest का उल्लेख करता है: सफलता: विफलता:' उदाहरण देखें [यहां] (https://github.com/AFNetworking/AFNetworking#readme)। – borisdiakur