nsrunloop

What is an NSTimer's behavior when the app is backgrounded?

淺唱寂寞╮ 提交于 2019-12-04 03:30:10
问题 I know that when you background an app, the timer stops running. However, what is the behavior when you come back from the background? Does the timer maintain its original fireDate ? I've run into a bit of an issue where upon returning from the background with an NSTimer set to fire in ten minutes, sometimes I'll immediately have the timer fire before applicationWillEnterForeground: is even called. When it doesn't fire, and applicationWillEnterForeground: is called, I have some logic to check

Stop an NSRunLoop

微笑、不失礼 提交于 2019-12-04 00:57:33
问题 I have a connection in a thread, so I add it to the run loop to get all data: [[NSRunLoop currentRunLoop] run]; [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; But I can't find any way to stop it - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ if([NSRunLoop currentRunLoop]){ [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self]; } [connection cancel]; } How can I stop this loop? 回答1: You can stop the runloop by Core

Should I use NSOperation or NSRunLoop?

为君一笑 提交于 2019-12-03 23:15:46
I am trying to monitor a stream of video output from a FireWire camera. I have created an Interface Builder interface with buttons and an NSImageView . While image monitoring is occurring within an endless loop, I want to: change some camera parameters on the fly (gain, gamma, etc.) tell the monitoring to stop so I can save an image to a file (set a flag that stops the while loop) Using the button features, I have been unable to loop the video frame monitor, while still looking for a button press (much like using the keypressed feature from C.) Two options present themselves: Initiate a new

Difference in usage of function sleep() and [[NSRunLoop currentRunLoop] runUntilDate]

岁酱吖の 提交于 2019-12-03 20:54:04
Please consider the following pieces of code: In the first one i call a function which creates an animation. i do that with a certain time interval: start:; [self animationMethod]; [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:3]]; //sleep(3); goto start; In the second one i create an animation - (void)animationMethod { CAKeyframeAnimation *myAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; CGMutablePathRef curvedPath = CGPathCreateMutable(); CGPathMoveToPoint(curvedPath, NULL, start.x, start.y); CGPathAddCurveToPoint(curvedPath, NULL, fcp.x,

NSRunLoop- Clarification needed

冷暖自知 提交于 2019-12-03 16:32:22
I am trying to understand the concept of RunLoops. I have read Apple developer's guide on RunLoops and to some extent I have understood the concept of RunLoops. To make my concept more clearer I wrote a very simple code which uses RunLoops in it. The code can be seen below. - (void)viewDidLoad { [super viewDidLoad]; thread = [[NSThread alloc] initWithTarget:self selector:@selector(testMethod) object:nil]; [thread start]; } - (void)testMethod { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Thread Entered"); NSMachPort* dummyPort = [[NSMachPort alloc] init]; [[NSRunLoop

How to wait in NSThread until some event occur in iOS?

狂风中的少年 提交于 2019-12-03 12:16:23
How to wait inside the NSThread until some event occur in iOS? eg, We created a NSThread and started a thread loop. Inside the thread loop, there is condition to check whether the message queue has any messages. If there is a message, then it will call the corresponding method to do some operation, else it should wait until the message queue gets populated with a new message. Is there any API or methods available to wait until some event occur? For Example NSThread *thread = [NSThread alloc]....@selector(threadLoop) - (void)threadLoop { // Expecting some API or method that wait until some

need some clarifications about dispatch queue, thread and NSRunLoop

此生再无相见时 提交于 2019-12-03 02:22:34
问题 The following things are what I know & understand: Global queue is a concurrent queue which can dispatch tasks to multiple threads. The order of executing task is not guaranteed. e.g.: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), { for (int i; i<10; i++) { doTask() } }) If I want to dispatch to serial queue, I can use dispatch_async(dispatch_queue_create("my.serial.queue", nil) { ... } each time only one task is dispatched to a thread & get executed. The order

need some clarifications about dispatch queue, thread and NSRunLoop

天大地大妈咪最大 提交于 2019-12-02 15:54:53
The following things are what I know & understand: Global queue is a concurrent queue which can dispatch tasks to multiple threads. The order of executing task is not guaranteed. e.g.: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), { for (int i; i<10; i++) { doTask() } }) If I want to dispatch to serial queue, I can use dispatch_async(dispatch_queue_create("my.serial.queue", nil) { ... } each time only one task is dispatched to a thread & get executed. The order is FIFO. ===== What I am confused & not fully understand ======= The main thread has a NSRunLoop,

How to test if a UIControlEvents has been fired

不问归期 提交于 2019-12-02 03:47:31
问题 I have a library implementing a custom UIControl with a method which would fire a .valueChanged event when called. I would like to test the method for that behavior. My custom control: class MyControl: UIControl { func fire() { sendActions(for: .valueChanged) } } And the test: import XCTest class ControlEventObserver: NSObject { var expectation: XCTestExpectation! init(expectation anExpectation: XCTestExpectation) { expectation = anExpectation } func observe() { expectation.fulfill() } }

NSProgressIndicator in NSMenuItem not updating on second display

随声附和 提交于 2019-12-02 02:05:31
I've got a NSMenu attached to a NSStatusItem (a menu bar application). While downloading a file I want to display a NSProgressIndicator in an item of this menu. I've created a NSViewController subclass for this progress indicator with the following properties: @property NSUInteger current; // Bound to NSProgressIndicator value @property NSString *status; // Bound to a NSTextField value @property NSUInteger total; // Bound to NSProgressIndicator max value When needed I start the download of the file with the following code, which runs in NSRunLoopCommonModes so that the delegate methods are