gpt4 book ai didi

iphone - iPhone 中每 60 秒调用一个方法

转载 作者:行者123 更新时间:2023-12-03 18:14:50 26 4
gpt4 key购买 nike

我创建了一个 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");
}

关于iphone - iPhone 中每 60 秒调用一个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5674375/

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