次のコードを使用して、サーバーに画像を投稿しています。
@IBAction func postButtonPressed(sender: UIButton) {
let task = NSURLSession.sharedSession().dataTaskWithRequest(createRequest("http://xx.xx.xxx.xxx/xxxx/"), completionHandler: {
data, response, error in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
})
task.resume()
}
wherecreateRequest()
は、必要な NSURLRequest オブジェクトを作成します。
シミュレーターを使用すると、これは正常に機能します。問題は、iPhone でアプリを実行すると、次のエラーが発生することです。
Error Domain=NSURLErrorDomain Code=-1001 "The operation couldn’t be completed. (NSURLErrorDomain error -1001.)" UserInfo=0x155e71f0 {NSErrorFailingURLKey=http://xx.xxx.xxx.xxx/xxxx/, NSErrorFailingURLStringKey=http://54.148.156.117/query/, NSUnderlyingError=0x155674d0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1001.)"}
このエラーはタイムアウト エラーであることがわかりました。アプリまたは電話を再起動しても解決しませんでした。さらに、Web ブラウザーからサーバーに画像を投稿しようとしましたが、問題なく動作しました。
このタイムアウト エラーの原因は何ですか?
編集:ネットワーク アクティビティを監視すると、送信している画像が 0.1 MB であっても、アプリが 10 MB のデータを送信していることに気付きました。