nsrunloop

Can an open, but inactive, NSStream that is scheduled on the main thread be moved to a different thread?

独自空忆成欢 提交于 2019-12-25 02:19:51
问题 I am using (and am required to use) a third-party framework to which I do not have source. The third-party framework handles creating an authenticated client/server connection and hands back a pair of open NSStreams. The challenge that I have is the NSStreams are scheduled on the main thread (creating situations where the UI may become unresponsive - which I would like to avoid). At the point that the streams are handed off from the third party framework, no network traffic is in progress. So

How to deal with concurrency issues brought by NSStream run loop scheduling using GCD?

核能气质少年 提交于 2019-12-23 18:19:36
问题 I have the following situation where I create a GCD dispatch queue and in it I schedule an NSStream to the current NSRunLoop , as is required in its specification for it to emit delegate events, and then I make the run loop for that thread run using [[NSRunLoop currentRunLoop run] . This generates three possible scenarios: Create a serial queue in which an initial write message is sent through the stream and other write messages are only sent when there's a delegate callback from the NSStream

NSURLConnection, NSOperation and NSRunLoop confusion over threading

痞子三分冷 提交于 2019-12-23 06:55:35
问题 I got confused while working with NSURLConnection and NSRunLoop. I’m trying to download a large file using NSURLConnection but it’s NOT working (Not even calling a single delegate method) as expected. NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8080/"]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease]; [request setHTTPBody:[@"Request Body Data" dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPMethod:@"POST"]; Running on main Thread.

What is the best way to poll data periodically from server when app is active in iOS in a separate thread?

末鹿安然 提交于 2019-12-20 10:37:01
问题 I need to poll data from server periodically in my iOS application. I need to do it every 10 seconds in a thread, in order to keep the UI usable. This function will be fired when the user logs in. I'm thinking about using NSRunLoop with NSTimer to achieve this functionality, and maybe use AFNetworking to get JSON data. Is this the correct approach? Should this be done using GCD? 回答1: Probably the only part that must be done off the main thread is the request itself. Deciding that you need a

CFRunLoopRun() vs [NSRunLoop run]

别说谁变了你拦得住时间么 提交于 2019-12-18 03:12:26
问题 I have an NSRunLoop object, to which I attach timers and streams. It works great. Stopping it is another story alltogether. I run the loop using [runLoop run] . If I try to stop the loop using CRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]) , the loop won't stop. If I start the loop using CRunLoopRun() instead, it works. I have also made sure that the call is made on the correct thread (the one running my custom run loop). I have debugged this with pthread_self() . I found a mailing

Order of operations in runloop on iOS

跟風遠走 提交于 2019-12-17 22:37:26
问题 What is the order of operations on iOS? I'm thinking sepcifically about timing of setNeedsLayout and layoutSubviews setNeedsDisplay and drawRect touch recognition [NSTimer scheduledTimerWithTimeInterval:0.000001 tar(...)] dispatch_async(dispatch_get_main_queue(), ^{ /* code */} As an example of an answer I would like to receive it could be in this format: dispatch_async on main Happens before the next runcycle drawRect Happens at the end of the runcycle 回答1: (Parts of this are copied from my

Using NSURLSession from a Swift command line program

 ̄綄美尐妖づ 提交于 2019-12-17 17:44:22
问题 I'm trying to test a little proof-of-concept command line app prior to integrating it into a larger app. What I'm trying to do is download some data using NSURLSession using this example. However it appears that if I use the examples given in a simple OS X command line app then the app exits prior to the data being retrieved. How can I download data from a stand-alone command line app using NSURLSession? What I've read about is using NSRunLoop however I've not yet found a clear example in

NSRunLoop cancelPerformSelectorsWithTarget's not working

烈酒焚心 提交于 2019-12-13 21:11:39
问题 I have this following code and I am not getting the results I expected. #import "CancelPerformSelectorTestAppDelegate.h" @implementation CancelPerformSelectorTestAppDelegate @synthesize window; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [window makeKeyAndVisible]; for(unsigned int i = 0; i < 10; i++){ NSTimeInterval waitThisLong = i; [self performSelector:@selector(foo) withObject:nil afterDelay: waitThisLong]; } [[NSRunLoop

do runloops/multi-threading/timers behave differently on iOS6?

跟風遠走 提交于 2019-12-13 18:21:35
问题 I just installed Xcode 4.5 to start testing some code on iOS6 devices.. I wanted my existing code to be runnable on both iOS 5 and iOS 6 obviously. The same code (below) that used to work on Xcode 4.3 stopped working on Xcode 4.5: -(BOOL)readFromRingBuffer { NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:0]; ringBufferReaderTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.25 target:self selector:@selector(readRingBufferDataBit) userInfo:NULL repeats:YES]; NSRunLoop

Waiting for condition to continue

别说谁变了你拦得住时间么 提交于 2019-12-13 12:49:11
问题 I have a method that I add to a GCD queue that I have created (so it's a serial queue) and then run it async. From within that block of code I make a dispatch to the main queue, when that block of code dispatched to the main queue is complete I set a BOOL flag to YES, so that I further down in my code can check if this condition is YES then I can continue to the next method. Here is the code in short: dispatch_queue_t queue = dispatch_queue_create("ProcessSerialQueue", 0); dispatch_async