3
我的在线广播应用程序正在播放背景音乐。当用户收听音乐并退出应用程序(进入后台)以查看其他地方时,我会拆除GKSession。它是P2P模式。当用户返回到应用程序时,我重新连接GKSession。如何正确处理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];
这就是我通常所做的,但我不确定这是否是最佳做法。 – msgambel