我正在开发一个应用程序,它会定期向选定的联系人发送SMS指定的次数。我有短信发送功能,但我需要在每轮发送短信之间加上延迟。
例如,如果我想在我的联系人中将消息M发送到S和D,我需要等待N秒才能再次向S和D发送相同的消息。
我怎样才能使这个工作?如何在向联系人发送消息之间添加延迟功能?
提前致谢!
答案 0 :(得分:5)
答案 1 :(得分:1)
是否可以将NSTimer设置为按特定时间间隔移动一定次数并让应用程序在关闭后在后台运行?
制作计时器:
int N = 3;
_myTimer = [NSTimer scheduledTimerWithTimeInterval:N target:self selector:@selector(myMethod) userInfo:myContact repeats:YES];
-(void)myMethod:(NSTimer*)timer {
// Now I can access all the properties and methods of myObject
[[timer userInfo] myObjectMethod];
}
在后台运行我并不熟悉,但是如果你开始寻找beginBackgroundTaskWithExpirationHandler:我相信你会找到你需要的答案。
希望这有帮助,祝你好运!
答案 2 :(得分:0)
好吧,如果您发现了短信发送功能,那么您只需要:
[self performSelector:@selector(sendSMS) withObject:nil afterDelay:5.0];
如果您的短信数据位于model
中的某个位置。如果您需要向sendSMS
方法发送一些数据,请使用:
[self performSelector:@selector(sendSMS:) withObject:objectData afterDelay:5.0];