Question

I am trying to make this runloop run forever(if not forever atleast for a single day) I am using the following function for runloop [self.runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:100000]];

The problem is that the app crashes after 3 hours.Can anybody help me?

Était-ce utile?

La solution

If you want it to run perpetually (and assuming you've attached timers and/or input sources), you can use

[self.runLoop run];

If you want to stay with your current construct, you can use:

[self.runLoop runUntilDate:[NSDate distantFuture]];

I've seen Apple use the following pattern (e.g. listing 3-14 of the Threading Programming Guide; I've also seen NSOperation objects use this construct when invoking an asynchronous operation that they want to wait to complete):

// Let the run loop process things.
do
{
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
                             beforeDate:[NSDate distantFuture]];
}
while ( ... ); // in here you have whatever condition you want to check for

Autres conseils

Try [NSDate distantFuture]. From the documentation: "An NSDate object representing a date in the distant future (in terms of centuries)."

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top