Hemant Sabale
Hemant Sabale

Reputation: 327

App works on Simulator but not on device.Https web service issue

I am fetching data through Post web service in my app. The app seems to work fine when i run it on simulator but fails on device. The service starts with https .. so do you guys think that could be the reason. The response data while i run on device is null and so the app crashes....Here is my code for the same for consuming web service and fetching the data ..

any help is appreciated as to how to consume https services.

+(NSDictionary *)checkWithServer:(NSString *)urlname jsonString:(NSString *)jsonInputString
{

    NSURL *url1 = [NSURL URLWithString:urlname];
    //NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url1];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url1 cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:60.0];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/json;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:[jsonInputString dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLResponse *response;
    NSError *err;

    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
    //       NSString *responseDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    //        NSLog(@"responseDataString %@",responseDataString);
    id jsonResponseData = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];

    NSDictionary *jsonResponseDict;

    if ([jsonResponseData isKindOfClass:[NSDictionary class]]) {
        jsonResponseDict = jsonResponseData;
    } else {
    }



    if (jsonResponseData == nil) {

        id jsonExceptioTypeData = [jsonResponseDict objectForKey:@"ExceptionType"];
        if (jsonExceptioTypeData != nil) {
            NSLog(@"%s ERROR : Server returned an exception", __func__);
            NSLog(@"%s ERROR : Server error details = %@", __func__, jsonResponseDict);
        }
    }
    else
    {

    }

    return jsonResponseData;
}

Upvotes: 0

Views: 650

Answers (1)

Related Questions