0

I am using NSURLConnection to communicate with a web service on my LAN. When using the Xcode Simulator everything works as expected. However, when using an iPhone the connection mostly times out (but not always).

The iPhone is connected to the LAN via wifi. I can consistently browse the web server (which is hosting the web service) using Safari.

However, the app mostly fails. It returns in the didFailWithError function reporting "The request timed out".

The app will intermittently succeed (behaving exactly as expected). I can see no pattern for success or failure. It may fail several times and then succeed and then fail again (without restarting the app). I estimate a 90%+ failure rate.

The web service always receives the request and always responds. It appears the failure happens with the device not receiving or handling the response.

I can see no obvious problem with my network. Certainly there is no IP address clash.

I am completely new to apps, Apple, Xcode and iPhone. So this could be something really very obvious to you. Any ideas what I could look at to resolve this?

The environment I'm currently using for development is as follows:

  • Mac OS X (10.7.4)
  • Xcode 4 (targetting 4.3)
  • iPhone 3GS (5.1.1)
4

1 に答える 1

0

明らかに、絶対的な答えを提供することはできませんが、問題を追跡するのに役立つことを願っています.

まず、Web サービスを精査します。JPEG 画像をパブリック Dropbox フォルダーに入れます。次に、コードを使用してその画像をダウンロードし、Safari で表示してみてください。Safari が機能するのにコードが機能しない場合は、コードに問題があることがわかります。

両方とも失敗した場合、電話のトランシーバーが不良であるか、WIFI ネットワークが不安定である可能性があります。電話を公共のWIFIの場所に持って行き、テストをやり直してください. 2 番目のネットワークで両方とも引き続き失敗する場合は、電話に問題がある可能性があります。

すべてのケースで Safari が機能するのにコードが機能しない場合は、できるだけ多くのコードを投稿してください。また、非同期インターフェースを使用している場合、リダイレクトされますか? 資格情報を求められましたか? などなど、すべての NSURLConnection デリゲート メソッドを追加し、少なくともログを追加して、何が起こっているかを把握できるようにしたいと考えています。つまり、すべての応答をログに記録します。応答から html リターン コードを取得することもできます。

assert([response isKindOfClass:[NSHTTPURLResponse class]]);
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; 
htmlStatus = [httpResponse statusCode];
if(htmlStatus != 200) NSLog(@"Server Response code %i", htmlStatus);
于 2012-08-17T12:53:05.047 に答える