在iPhone中每60秒后调用一次方法(calling a method after each 60 seconds in iPhone)
我创建了一个GKSession,创建它的对象后,它开始搜索设备的可用性,如
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {我想在每60秒后调用一次该方法,我该怎么办?
I have created an GKSession and as its object is created, it starts search for availability of devices, as
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {I want to call this method after each 60 seconds, what should I do?
最满意答案
使用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"); }Use NSTimer
NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval: 60.0 target: self selector: @selector(callAfterSixtySecond:) userInfo: nil repeats: YES];After each 60.0 second , iOS will call the below function
-(void) callAfterSixtySecond:(NSTimer*) t { NSLog(@"red"); }更多推荐
发布评论