首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确处理GKSession的中断?

如何正确处理GKSession的中断?
EN

Stack Overflow用户
提问于 2012-11-22 02:09:09
回答 1查看 248关注 0票数 3

我的在线广播应用程序正在播放背景音乐。当用户听音乐并退出应用程序(进入后台)以查看其他地方时,我会关闭GKSession。这是P2P模式。当用户返回应用程序时,我重新连接GKSession。

这是正确的事情吗?如果电话打来或发生其他中断,该怎么办?同时杀死GKSession并重新创建?

代码语言:javascript
复制
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

    // Register for notifications when the application leaves the background state
    // on its way to becoming the active application.
    [defaultCenter addObserver:self 
                      selector:@selector(setupSession) 
                          name:UIApplicationWillEnterForegroundNotification
                        object:nil];

    // Register for notifications when when the application enters the background.
    [defaultCenter addObserver:self 
                      selector:@selector(teardownSession) 
                          name:UIApplicationDidEnterBackgroundNotification 
                        object:nil];
EN

回答 1

Stack Overflow用户

发布于 2013-12-21 04:08:49

你做得对。当你的应用程序处于后台模式时,所有线程都会挂起,包括GKSession的线程。

当你的应用程序处于“非活动”模式时(例如,当它被一个电话中断时,等等),GKSession仍然可以工作。Inactive表示应用程序仍在前台运行,但不接收事件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13499438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档