在 iPhone 中每 60 秒调用一个方法 [英] calling a method after each 60 seconds in iPhone

查看:25
本文介绍了在 iPhone 中每 60 秒调用一个方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个 GKSession 并且当它的对象被创建时,它开始搜索设备的可用性,如

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 {

我想每60秒调用一次这个方法,怎么办?

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 将调用以下函数

After each 60.0 second , iOS will call the below function

-(void) callAfterSixtySecond:(NSTimer*) t 
{
    NSLog(@"red");
}

这篇关于在 iPhone 中每 60 秒调用一个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆