GKSession を作成しました。そのオブジェクトが作成されると、デバイスの可用性の検索が開始されます。
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {
このメソッドを 60 秒ごとに呼び出したいのですが、どうすればよいですか?
使用するNSTimer
NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval: 60.0 target: self
selector: @selector(callAfterSixtySecond:) userInfo: nil repeats: YES];
60.0 秒ごとに、iOS は以下の関数を呼び出します。
-(void) callAfterSixtySecond:(NSTimer*) t
{
NSLog(@"red");
}
NSTimer を scheduleWithTimeInterval に設定すると、すぐに呼び出されます。使用できます
[self performSelector:@selector(doSomething) withObject:nil afterDelay:60.0f];
スウィフト 3:
Timer.scheduledTimer(withTimeInterval: 60, repeats: true, block: { (timer) in
print("That took a minute")
})
あなたはスケジュールされた方法を使うことができます...
-(void) callFunction:(CCTime)dt
{
NSLog(@"Calling...");
}
これを使用して上記の関数を呼び出すことができます...
[self schedule:@selector(callFunction:) interval:60.0f];