3

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

1 に答える 1

0

あなたはそれを正しくやっています。アプリがバックグラウンド モードの場合、 を含むすべてのスレッドが中断されますGKSession

GKSessionアプリが「非アクティブ」モードの場合 (電話などで中断された場合など) も機能します。非アクティブとは、アプリがまだフォアグラウンドで実行されているが、イベントを受信して​​いないことを意味します。

于 2013-12-20T20:08:48.993 に答える