简体   繁体   中英

NSThread work on simulator but not on device

I have an application that connects to some server to get data. Well I'm using NSThreads and seems work perfectly in simulator. once I installed the application on my iPhone device it stops working.

I don't know if it is a common problem.If yes what can be the alternative to NSThread ?

NOTE: I tried NSOperations but still get the same problem.

If both NSThread and NSOperation aren't working then you have some more fundamental problem with your code. Both of those work equally well on device and simulator (indeed they'd be a bit pointless otherwise). I highly recommend you investigate the apparent issue more closely. It's much, much more likely that you have some sort of race condition that the particular timing you get on your device with the current version of the OS triggers while your simulator with the current version of the SDK doesn't. The most common error made on iOS in this area is probably failure to observe that UIKit is in the main part usable on the main thread only.

But to answer the question exactly as put: the main alternatives for performing work asynchronously are:

Note also that NSURLConnection has an asynchronous mode of operation built in that reports to the main thread, which means you don't actually have to do anything explicit for yourself. Apple strongly recommend you use that rather than building your own system, since it's written to be much more power and processor efficient than an NSThread solution could be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM