English 中文(简体)
ASIHTTPRequest synchronously
原标题:

I have an iPhone app which uses ASIHTTPRequest to communicate to a REST service on my server. When I m running on the simulator, it works just fine, but when I get onto the phone itself, I get weird behavior.

The very first time I click the button that initiates the request, I get the results back immediately, and all is fine. From that point on, when I click the button to initiate the connection it takes about 2-3 minutes to connect. It almost seems like the ASIHTTPRequest that I kicked off first (and from which I ve already received the correct results) has not completed. Is there some sort of magic I need to use to terminate the original request before starting the next one? I assumed that since the -start method returned, and I have results from the server that the original request was completed and I could start another.

Any ideas?

Thanks

--Steve

最佳回答

You re not suppose to call the -start method, it belongs to the NSOperation. The ASIHTTPRequest interface is either -startSynchronous or -startAsynchronous.

However, it s highly recommend to use the asynchronous call otherwise, your main thread (ie., UI) will be blocked.

From the ASIHTTPRequest documentation[1]

In general, you should use asynchronous requests in preference to synchronous requests. When you use ASIHTTPRequest synchronously from the main thread, your application s user interface will lock up and become unusable for the duration of the request. Synchronous requests are only really suitable for software without a UI (like a script that runs from the terminal), or if you are running the request from a separate thread that you maintain (perhaps from inside your own NSOperation, for example).

[1] http://allseeing-i.com/ASIHTTPRequest/How-to-use

问题回答

Steve - What you ve described is a common problem that will occur if the requests are attempting to keep a persistent connection. Try this out:

[request setShouldAttemptPersistentConnection:NO];




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签