Questions tagged [nsrunloop]

NSRunLoop is a class in Apple's Foundation framework. It processes inputs such as user events, network activity, and NSTimer events.

NSRunLoop is a class in Apple's Foundation framework for OS X and iOS. It processes inputs such as user events, network activity, and NSTimer events. Each NSThread object automatically receives its own NSRunLoop; apps cannot explicitly create or manage NSRunLoop objects.

353 questions
12
votes
1 answer

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

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…
amb
  • 4,798
  • 6
  • 41
  • 68
11
votes
1 answer

how to stop a timer triggered runloop?

if i set up a runloop like that: NSRunloop* loop = [NSRunloop currentRunLoop]; [runLoop addTimer:anyTimer forMode:NSDefaultRunLoopMode]; can i stop it again ? or is the only way to ignore the notification i use to trigger the further action ? ok, i…
nico
  • 1,039
  • 4
  • 13
  • 27
10
votes
3 answers

PerformSelector After delay doesn't run in background mode - iPhone

I have a voip application which runs constantly on the background as well. While I'm in the background I'm calling from the main thread: (to establish network connection in case I diagnose a network lost). [self performSelector…
Idan
  • 5,717
  • 10
  • 47
  • 84
10
votes
4 answers

iOS5 crashes during runMode:beforeDate:

I have a problem with compatibility of my application with an iOS5 b7 and GM versions. The issue occurs in the next lines of code: do { [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; } while…
Nekto
  • 17,837
  • 1
  • 55
  • 65
10
votes
3 answers

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

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…
Bharath
  • 198
  • 1
  • 1
  • 9
10
votes
2 answers

Performing selector at beginning / end of run loop

All events and methods in iOS are processed using NSRunLoop: user events, method calls, rotations, timers, connections, etc. My question is: How can I perform a selector in a precise moment of the run loop as the beginning and the end?
vilanovi
  • 2,097
  • 2
  • 21
  • 25
10
votes
2 answers

Stop an NSRunLoop

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 -…
Makio
  • 465
  • 6
  • 15
10
votes
2 answers

What is the correct way of setting the current thread NSRunLoop to run in a certain mode until I decide to stop it?

I want to mimic the UIScrollView behavior where the current thread RunLoop mode changes to UITrackingRunLoopMode when you drag the scrollView, and back to NSDefaultRunLoopMode when you stop dragging. I want to do it with my own class, though,…
LocoMike
  • 5,626
  • 5
  • 30
  • 43
9
votes
2 answers

Is calling -[NSRunLoop runUntilDate:] a good idea?

Is it generally a good idea to call -[NSRunLoop runUntilDate:]? It seems to work without any issues, but it makes me nervous to tell the run loop to run from within the run loop. More info: I have a project right now that is fetching data from a…
Jose Ibanez
  • 3,325
  • 3
  • 28
  • 33
9
votes
2 answers

Timer in another thread in Objective - C

I have to define method which should be invoked periodically with some time interval. I need to invoke it in another thread (NOT main thread), because this method is used to get information from external API and sync data in core data. How do I…
user2375706
  • 705
  • 2
  • 8
  • 14
9
votes
2 answers

scheduleInRunLoop - threading network connections

I've not found any decent documentation that explains the threading process for NSStream. To be specific, let's go for NSInputStream. Threading in Objective-C to me is currently a mystery simply because it appears to be so simple. What my question…
Kieran Senior
  • 17,960
  • 26
  • 94
  • 138
8
votes
4 answers

iOS, NSURLConnection: Delegate Callbacks on Different Thread?

How can I get NSURLConnection to call it's delegate methods from a different thread instead of the main thread. I'm trying to mess around with the scheduleInRunLoop:forMode:but doesn't seem to do what I want. I have to download a large file and it…
gngrwzrd
  • 5,902
  • 4
  • 43
  • 56
8
votes
2 answers

Should a NSTimer always be added into a runloop to execute

I didn't explicitly add timers to a runloop and it works just fine. The other day when I read some article about NSRunLoop and it said it's better to add a NSTimer instance into a runloop instance to execute. I just wonder will it do any harm if I…
Xin Yuan
  • 255
  • 1
  • 8
8
votes
3 answers

Xamarin Android: Keep control with Alert Dialog until a button is clicked

We are using a static Alert Dialog to get confirmation from the user for certain actions. In our call to Show() we want to keep control until the user clicks a button so that we can return the button click result at the end of the Show() call. Our…
my code smells
  • 461
  • 5
  • 14
7
votes
3 answers

Order of operations in runloop on iOS

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…
hfossli
  • 22,616
  • 10
  • 116
  • 130
1
2
3
23 24