0

良い一日!

ネットワークアクセス用の関数を呼び出し、ネットワークが存在するかどうかを確認する xcode のプロジェクトで nsthreads を使用したいので、1 分後に実行するスレッドが必要です。接続性。アプリを閉じない限り実行され続けます。

[NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil];

startTheBackgroundJob

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// wait for 3 seconds before starting the thread, you don't have to do that. This is just an example how to stop the NSThread for some time
[NSThread sleepForTimeInterval:5];
//[self performSelectorInBackground:@selector(checkNet) withObject:nil];
[self performSelectorOnMainThread:@selector(checkNet) withObject:nil waitUntilDone:YES];
[pool release];

それは初めて機能しますが、他の機能はありません。つまり、ループは1つだけです

誰かがこの点で私を助けることができます.

ありがとう

4

3 に答える 3

1

代わりに NStimer を使用できます... Property Repeated を YES に設定

于 2010-05-04T12:11:57.723 に答える
1

スレッドは、時間のかかるタスクを実行する必要があるが、アプリケーションの残りの実行をブロックしたくない場合に特に便利です。特に、スレッドを使用して、アプリケーションのメイン スレッドをブロックしないようにすることができます。

もっと理解するには.... http://www.xprogress.com/post-36-threading-tutorial-using-nsthread-in-iphone-sdk-objective-c/からシンプルで短いソースコードを見つけてください

于 2012-07-18T06:35:51.233 に答える
0

5 ~ 10 秒ごとに起動する NSTimer + ネットワークの状態をチェックする Reachability インターフェイスの組み合わせをお勧めします。スレッドは必要ありません。到達可能性を使用するには、Apple の例を確認してください。

この呼び出しをviewDidLoadに入れます

[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];

-(void) onTimer:(NSTimer *)theTimer 
{
    //Here perform reachability checks
}
于 2010-05-04T12:49:41.637 に答える