views:

686

answers:

4

I'm testing iphone application via xCode both simulation and on iphone device. On the simulation, there is no problem, but when running on the iphone device, NSURLConnection fails, connection:didFailWithError: method called.

What can be the reason for this problem?

+1  A: 

Find out by inspecting the NSError object that you receive in connection:didFailWithError:. See listing 3 over at the Using NSUrlConnection documentation:

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{

    [connection release];
    [receivedData release];

    NSLog(@"Connection failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}
MathieuK
Thanks for your reply, the problem occurs because of internet connection, error says no internet connection. I want to ask about iphone download. When the iphone is connected via cable to the mac and runs via xcode, is download be made over the mac's internet connection or iphone's connection?
crazywood
I'm not entirely sure, but I'd say it's using the iPhone's connection.
MathieuK
ok thanks very much, it's using iPhone's connection, because i provide iPhone's connection and the internet connection problem is gone, but unfortunately there is time-out problem :((
crazywood
A: 

I have the same problem too. I want to download data from FTP service. It goes well when debugging by similator, but the time out error happens by device.

Which technology does iphone use to connect to internet? Edge, wifi or 3g? i can connect with my carrier via edge, but when i connect via 3g, problem is solved.
crazywood
A: 

I am having a similar problem too it works perfect on the sim but once it's on the device it times out

A Person
A: 

When you use the phone it is connecting through the phone's internet connection. When on the simulator it uses your computer's internet connection.

If there is a problem it is probably with the connection on the phone to whatever your connecting to. Maybe what ever your connecting to is blocking your phone? It's probably not a problem with the application if it works on the simulator.

Conceited Code