I'm trying to connect to a service using https://
. When I'm entering correct user credentials it's working well. But when I'm entering invalid user credentials, It's giving me an error,
Error Domain=NSURLErrorDomain Code=-1012 "(null)" UserInfo={NSErrorFailingURLStringKey=https://api.myapp.com/myapp/mobile/signIn, NSUnderlyingError=0x1018f0530 {Error Domain=kCFErrorDomainCFNetwork Code=-1012 "(null)" UserInfo={_kCFURLErrorAuthFailedResponseKey={url = https://api.myapp.com/myapp/mobile/userCredentialNotMatching}}}, NSErrorFailingURLKey=https://api.myapp.com/myapp/mobile/signIn}
When this error is coming, all http header and response is nil.
NSString *body = [NSString stringWithFormat:@"email=%@&password=%@&device=%@&platform=%@&authType=%@&latitude=%@&longitude=%@", email, password, deviceId, PLATFORM, APP_TYPE, latitude, longitude];
[request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"response status code: %ld", (long)[httpResponse statusCode]);
NSDictionary *allHeaderFields;
allHeaderFields = [(NSHTTPURLResponse *) response allHeaderFields];
if (data.length > 0 && connectionError == nil)
{
if ((long)[httpResponse statusCode] == 200)
{
NSError *jsonError = nil;
NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"response status code: %@", newStr);
NSDictionary *responceDic =[NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
// NSMutableArray *convertedDiscussion =[[NSMutableArray alloc] init];
[defaults setObject:email forKey:USER_DEFAULTS_KEY_EMAIL];
[defaults setObject:password forKey:USER_DEFAULTS_KEY_PASSWORD];
[defaults setObject:[responceDic objectForKey:@"nickName"] forKey:USER_DEFAULTS_KEY_USERNAME];
[defaults setObject:[responceDic objectForKey:@"profileImgUrl"] forKey:USER_DEFAULTS_KEY_PROFILE_PIC];
[defaults setObject:[responceDic objectForKey:@"isPremiumUser"] forKey:USER_DEFAULTS_KEY_PREMIUM];
[defaults setObject:[[responceDic objectForKey:@"userMetaData"] objectForKey:@"noOfActivities"] forKey:USER_DEFAULTS_KEY_META_DATA];
[defaults synchronize];
[[Branch getInstance] setIdentity:[NSString stringWithFormat:@"%@", [responceDic objectForKey:@"ninjaName"]]];
BTDiscussion *convertedDiscussion = [self discussionObjectsFromJson:responceDic];
completion ([allHeaderFields objectForKey:NINJA_MESSAGE],convertedDiscussion, connectionError);
}else
{
completion (@"Your account is still not activated. Please check your email and verify the email address to activate the account.",nil, connectionError);
}
}
else
{
completion (@"Your account is still not activated. Please check your email and verify the email address to activate the account.", nil, connectionError);
}
}];
Here what I did to log in to the app. How may I fix this?