错误域= NSURLErrorDomain代码= -1012“(null)”

时间:2016-01-07 10:43:00

标签: ios objective-c nsurlconnection

我正在尝试使用https://连接到服务。当我输入正确的用户凭据时,它运行良好。但是当我输入无效的用户凭据时,它给了我一个错误,

  

错误域= NSURLErrorDomain代码= -1012“(null)”UserInfo = {NSErrorFailingURLStringKey = https://api.myapp.com/myapp/mobile/signIn,NSUnderlyingError = 0x1018f0530 {错误域= kCFErrorDomainCFNetwork代码= -1012“(null)”UserInfo = {_ kCFURLErrorAuthFailedResponseKey = { url = https://api.myapp.com/myapp/mobile/userCredentialNotMatching}}},NSErrorFailingURLKey = https://api.myapp.com/myapp/mobile/signIn}

当出现此错误时,所有http标头和响应都为零。

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);
    }
}];

这是我登录应用程序所做的工作。我该如何解决这个问题?

0 个答案:

没有答案