我试图让这个runloop永远运行(如果不是永远至少一天)我正在使用以下函数进行runloop [self.runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:100000]];
问题是应用程序在3小时后崩溃。任何人都可以帮助我吗?
答案 0 :(得分:2)
如果您希望它永久运行(假设您已经附加了计时器和/或输入源),您可以使用
[self.runLoop run];
如果您想继续使用当前构造,可以使用:
[self.runLoop runUntilDate:[NSDate distantFuture]];
我见过Apple使用以下模式(例如列出Threading Programming Guide的3-14;我也看到NSOperation
对象在调用他们想要等待的异步操作时使用此构造完成):
// 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
答案 1 :(得分:1)
试试[NSDate distantFuture]
。从文档:“一个NSDate对象代表遥远未来的日期(以几个世纪为代表)。”