iOS xcode,Web服务,NSURLConnection第二次调用失败
iPad 开发、iOS 4.3、objective-c、xcode 4.1。
我创建了一个包装类,用于调用 Web 服务上的方法。当我进行第一次调用时它工作正常,但在后续调用时失败。
我的类中的方法“runMethod::”打开一个 NSURLConnection 并异步执行调用,其中包装类本身作为 NSURLConnection 委托。
我在某处读到过,Android 存在一个错误,它会保留连接池。当您尝试第二次建立连接时,它会失败,因为前一个连接一直保持打开状态,尽管代码将其关闭。因此,我怀疑问题在于连接保留在池中,当我尝试建立另一个连接时它会发生冲突吗?也许xcode也有类似的问题?
失败的症状是委托选择器之一的随机行上看似随机的“错误访问”,这表明这与线程有关 - 我知道 HTTP 连接在其自己的线程上运行。
如果需要,我可以提供完整的包装类,但有人有什么想法吗?
iPad development, iOS 4.3, objective-c, xcode 4.1.
I have created a wrapper class, which is used to call a method on a web service. It works fine when I make the first call, but fails on subsequent calls.
A method in my class, "runMethod::", opens a NSURLConnection and does the call asynchronously, with the wrapper class itself as the NSURLConnection delegate.
I have read somewhere that there's a fault with Android, which keeps a pool of connections. When you try to make a connection a second time it fails because the previous connection has been kept open, despite the code closing it. Hence, I suspect the problem is that the connection remains in the pool, and when I try to make another one it clashes? Maybe xcode has a similar issue?
And the symptoms of the failure are a seemingly random 'bad access' on a random line in one of the delegate selectors, which suggests this has something to do with threading - I understand that HTTP connections operate on their own thread.
I can provide the full wrapper class if need be, but anyone any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“错误访问”错误仅表明您正在取消引用无效的指针。这通常是由于内存管理不当造成的,例如未能保留某些对象。代码会有所帮助,但首先尝试 Xcode 中的“分析”命令——静态分析器非常擅长查找内存问题。
A 'bad access' error simply indicates that you're dereferencing an invalid pointer. This is most often due to improper memory management, such as failing to retain some object. Code would help, but first try the Analyze command in Xcode -- the static analyzer is pretty good at finding memory problems.