I have an iOS app that requests JSON
data from my Rails 3 app, hosted on Heroku, and it works great on my device and for many other users, except one. I have one user who has told me that my app fails to retrieve the JSON data, so I had her send me some log data and the log showed the NSURLConnection
delegate method didFailWithError
is being called and the error description reads "bad URL". Why is this error occurring and why is it ONLY occurring on just some devices instead of all devices?
Here's my code,
-(void)getTournamentInfoWithUsername:(NSString*)username
{
NSString *urlString = [NSString stringWithFormat:@"http://myapp-tourney.heroku.com/tournaments/next.json?username=%@", username];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
[self setUrlConnection:[[NSURLConnection alloc] initWithRequest:request delegate:self]];
}
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
{
[MyLog logError:[NSString stringWithFormat:@"%@ - %@ - %@ - %@", [error localizedDescription], [error localizedFailureReason], [error localizedRecoveryOptions], [error localizedRecoverySuggestion]]];
}
and the log shows...
bad URL - (null) - (null) - (null)
Thanks so much for all your wisdom!
It doesn't look like you are encoding the username. Are there spaces or other special characters in the username? Look into using the NSString
method stringByAddingPercentEscapesUsingEncoding:
.