在 iPhone 上尝试 SimplePing,但主运行循环不处理来自 SimplePing 的事件
我需要在 iPhone 上进行简单的 ping 操作。所以我尝试让 SimplePing 示例 运行在iPhone。但是当我像示例中那样初始化 pinger 时,主运行循环不会处理 SimplePing 生成的事件。这是初始化代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_pinger = [SimplePing simplePingWithHostName:@"192.168.210.1"];
_pinger.delegate = self;
[_pinger start];
NSLog(@"Pinger started");
[self.window makeKeyAndVisible];
return YES; }
如果我用类似的东西直接在这个函数中触发运行循环:
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (_pinger != nil);
它可以工作。所以我的问题是,为什么这些事件没有在 UIApplicationMain 的主运行循环中处理,我需要做什么才能由主运行循环完成此操作?
I need a simple pinger on the iPhone. So I try to get the SimplePing example running on iPhone. But when i init the pinger like in the example, the main runloop does not handle the events generated by SimplePing. Here is the initcode:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_pinger = [SimplePing simplePingWithHostName:@"192.168.210.1"];
_pinger.delegate = self;
[_pinger start];
NSLog(@"Pinger started");
[self.window makeKeyAndVisible];
return YES; }
If I trigger the runloop directly in this function with somthing like that:
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (_pinger != nil);
it works. So my question is, why are the events not processed in the main run loop of UIApplicationMain
, and what do I have to do to get this done by the main runloop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,做这样的事情:
Well, do something like this: