gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 17:47:47 25 4
gpt4 key购买 nike

我需要一个简单的 iPhone pinger。所以我尝试获取 SimplePing example在 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 的主运行循环中处理,我需要做什么才能让主运行循环完成?

最佳答案

好吧,做这样的事情:

-(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 ..


}

关于iphone - 在 iPhone 上尝试 SimplePing,但主运行循环不处理来自 SimplePing 的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4439937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com