【问题标题】:Stop setKeepAliveTimeout handler from being called after application came foreground?应用程序进入前台后停止调用 setKeepAliveTimeout 处理程序?
【发布时间】:2013-09-04 06:03:58
【问题描述】:

对于 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 分钟接到一次电话。这个怎么处理,我只需要使用flag吗?

非常感谢任何帮助。

【问题讨论】:

    标签: iphone ios cocoa-touch appdelegate


    【解决方案1】:

    你可以这样做

    - (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];
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2013-12-13
        • 2014-12-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多