Question

This is my code to retrieve data from a MySQL table using JSON:

//URL definition where php file is hosted

    int categoriaID = [[categoriaDescription objectForKey:@"idCategoria"] intValue];

    NSString *string = [NSString stringWithFormat:@"%d", categoriaID];
    NSLog(@"CATEGORIA ID STRING %@",string);
    NSMutableString *ms = [[NSMutableString alloc] initWithString:@"http://mujercanariasigloxxi.appgestion.eu/app_php_files/categoriaslist.php?id="];
    [ms appendString:string];
    // URL request
    NSLog(@"URL = %@",ms);
    NSURLRequest *request = [NSURLRequest requestWithURL:ms];
    //URL connection to the internet
    [[NSURLConnection alloc]initWithRequest:request delegate:self];

The URL logged is correct, but the app throws an exception:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance 

I guess the error should be in the above code, but I don't see why. Any help is welcome.

Was it helpful?

Solution

I think your code is wrong.

NSURLRequest *request = [NSURLRequest requestWithURL:ms];

It should be change to:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:ms]];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top