在iPhone中每60秒后调用一次方法(calling a method after each 60 seconds in iPhone)

编程入门 行业动态 更新时间:2024-10-25 22:30:41
在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"); }

更多推荐

本文发布于:2023-07-29 20:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   iPhone   seconds   method   calling

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!