1

对于 VOIP 应用程序,我们使用 setKeepAliveTimeout 每 10 分钟向服务器发送一次 PING 数据包,一切正常,但是我不确定如何在应用程序进入前台后停止调用处理程序。

例如:这是我设置超时的方式

 [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{ [self backgroundHandler]; }];

后台处理程序:

- (void)backgroundHandler
{
    printf("10 minute time elapsed\n");
    // do some action...
}

即使在应用程序出现在前台之后也会调用上述函数,我已阅读 Apple 文档以将处理程序设置为 nil 以停止它。我在 applicationWillEnterForeground 中尝试过如下

[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:nil];

我仍然每 10 分钟接到一次电话。如何处理,我是否只需要使用标志。

非常感谢任何帮助。

4

2 回答 2

4

你可以这样做

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    [[UIApplication sharedApplication] clearKeepAliveTimeout];
}
于 2013-09-04T06:24:32.990 回答
2

您必须调用clearKeepAliveTimeout以停止计时器。setKeepAliveTimeout:旨在保持 voip 连接,这就是它定期调用的原因。

于 2013-09-04T06:21:51.120 回答