在 iPhone 上尝试 SimplePing,但主运行循环不处理来自 SimplePing 的事件

发布于 2024-10-07 16:37:23 字数 828 浏览 0 评论 0原文

我需要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○闲身 2024-10-14 16:37:23

好吧,做这样的事情:

-(void)stopPinging
{

 NSLog(@"STOP");

 self.pinger = nil;  // or _pinger = nil in your case so that the while loop doesn't   execute again.

 [self.pinger stop]; // this method will call the Simpleping class method stop which takes care of the rest ..


}

Well, do something like this:

-(void)stopPinging
{

 NSLog(@"STOP");

 self.pinger = nil;  // or _pinger = nil in your case so that the while loop doesn't   execute again.

 [self.pinger stop]; // this method will call the Simpleping class method stop which takes care of the rest ..


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文