私のオンラインラジオアプリはバックグラウンドミュージックを再生しています。ユーザーが音楽を聴き、アプリを終了して(バックグラウンドに入って)他の場所を探すとき、私は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];