i'm very new in iOS app development.I am going to use AFNetworking 3.0. On first view when i enter mobile no. and click on submit button then it connect with server and i get following response from server:
responseData: [{"edriverId":"bd307a3ec329e10a2cff8fb87480823da114f8f4","token":"6uc4d1houfecbmjgy9ezpru9n25nw40b17cwk439j52"}]
now my question is,how can i take only that token from responseData and send it to server from next view. Please help me.
NOTE:whenever we call service token changes every time.
my code is:
-(void)serverconnection
{
NSString *Loginurl = [NSString stringWithFormat:@"https://24x7tracker.com/busservices/School/DriverPreLogin"];
NSDictionary *params = @{@"mobile":self.phonenumber.text,
@"archive":@"schooldb1"
};
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
AFSecurityPolicy* policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
[policy setValidatesDomainName:NO];
[policy setAllowInvalidCertificates:YES];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",nil];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/plain",nil];
[manager POST:Loginurl parameters:params progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"Json: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
[self getdata:responseObject];
NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"responseData: %@", str);
[self performSegueWithIdentifier:@"loginsegue" sender:self];
}
failure:^(NSURLSessionTask *operation, NSError *error)
{
NSLog(@"Error: %@", error);
UIAlertController *Erroralert= [UIAlertController
alertControllerWithTitle:@" Network Connection Failed!!"
message:@"Please try again"
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:Erroralert animated:YES completion:nil];
UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[self resignFirstResponder];
[Erroralert dismissViewControllerAnimated:YES completion:nil];
}];
[Erroralert addAction: yesButton];
}];
}
-(void)getdata:(NSData *)data
{}