我的在线广播应用正在播放背景音乐。当用户听音乐并退出应用程序(进入后台)以查看其他位置时,我会拆除 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];