0

I think my problem is like the one described here but I cannot quite understand the answer.

My app requires users to enter the URL of a site that contains .pbn files. But the same URL which works manually, does not work when entered in the TextField in my app. In my example case self.urlNameInput.text is http://www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn and the URL is not recognized.

NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlNameInput.text] cachePolicy:NSURLRequestUseProtocolCachePolicy
                                              timeoutInterval:60.0];

Depending on whether I include or exclude 'http://' I get the following error messages.

Connection failed! Error - A server with the specified hostname could not be found. http://www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn

Connection failed! Error - unsupported URL www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn

Community
  • 1
  • 1
zerowords
  • 2,915
  • 4
  • 29
  • 44

1 Answers1

1

This seems to work just fine:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn"]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    NSString *results = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"Results:%@", results);
}];
Steven Hepting
  • 12,394
  • 8
  • 40
  • 50
  • Yes, before I had the TextField I used the following successfully, too, but now I get problems with the TextField entry. `NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.atlantaduplicatebridgeclub.com/scorepost/2013/01/20130126ana.pbn"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];` – zerowords Mar 02 '13 at 00:24
  • Thank you. I got the download to work, but I have a related question. Can I now eliminate the following delegate methods: connection:didReceiveResponse:, connection:didReceiveData:, connection:didFailWithError: and connectionDidFinishLoading: because you are using another route? Or can I somehow hook up your approach to those delegate methods? – zerowords Mar 02 '13 at 18:35
  • [This answers my question about delegate methods](http://stackoverflow.com/questions/15181633/). – zerowords Mar 03 '13 at 11:56