我的在线广播应用程序正在播放背景音乐。当用户听音乐并退出应用程序(进入后台)以查看其他地方时,我会关闭GKSession。这是P2P模式。当用户返回应用程序时,我重新连接GKSession。
这是正确的事情吗?如果电话打来或发生其他中断,该怎么办?同时杀死GKSession并重新创建?
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];发布于 2013-12-21 04:08:49
你做得对。当你的应用程序处于后台模式时,所有线程都会挂起,包括GKSession的线程。
当你的应用程序处于“非活动”模式时(例如,当它被一个电话中断时,等等),GKSession仍然可以工作。Inactive表示应用程序仍在前台运行,但不接收事件。
https://stackoverflow.com/questions/13499438
复制相似问题