1

iPhone で簡単なピンガーが必要です。そこで、SimplePing の例 を iPhone で実行してみます。しかし、例のようにピンガーを初期化すると、メインの実行ループは 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; }

この関数で runloop を直接トリガーすると、次のようになります。

do {
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (_pinger != nil);

できます。私の質問は、イベントが のメイン実行ループで処理されないのはなぜですか? また、メイン実行ループでUIApplicationMainこれを実行するにはどうすればよいですか?

4

1 に答える 1

0

さて、次のようなことをしてください:

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


}
于 2011-11-14T15:06:38.423 に答える